I think this issue is related to: #160
I have been using BTrace to trace a Java application, my BTrace script/class is:
package com.negafinity.btrace;
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.Profiler;
import com.sun.btrace.annotations.BTrace;
import com.sun.btrace.annotations.Duration;
import com.sun.btrace.annotations.Kind;
import com.sun.btrace.annotations.Location;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.OnTimer;
import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.Property;
@BTrace
public class Logger
{
@Property
static Profiler profiler = BTraceUtils.Profiling.newProfiler();
@OnMethod(clazz = "/^(?!sun|java).*$/", method = "/.*/")
public static void entry(@ProbeMethodName(fqn = true) String probeMethod)
{
BTraceUtils.Profiling.recordEntry(profiler, probeMethod);
}
@OnMethod(clazz = "/^(?!sun|java).*$/", method = "/.*/", location = @Location(value = Kind.RETURN))
public static void exit(@ProbeMethodName(fqn = true) String probeMethod, @Duration long duration)
{
BTraceUtils.Profiling.recordExit(profiler, probeMethod, duration);
}
@OnTimer(300000)
public static void timer()
{
BTraceUtils.println("Logging Time: " + BTraceUtils.Time.millis() + " " + BTraceUtils.timestamp());
BTraceUtils.Profiling.printSnapshot("Profiler Output:", profiler);
}
}
The issue I'm having is while the application is running, it sometimes crashes with this exception:
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
com/pixelmonmod/pixelmon/entities/pixelmon/helpers/EvolutionQuery.updateAllAround(Lcom/pixelmonmod/pixelmon/comm/packetHandlers/evolution/EvolutionStage;)V @39: getfield
Reason:
Type 'java/lang/Object' (current frame, stack[2]) is not assignable to 'net/minecraft/entity/EntityLivingBase'
Current Frame:
bci: @39
flags: { }
locals: { 'com/pixelmonmod/pixelmon/entities/pixelmon/helpers/EvolutionQuery', 'com/pixelmonmod/pixelmon/comm/packetHandlers/evolution/EvolutionStage', long, long_2nd, long, long_2nd, 'java/lang/Object' }
stack: { uninitialized 33, uninitialized 33, 'java/lang/Object' }
Bytecode:
0x0000000: 0941 b802 8e37 0413 02ac b802 882a b400
0x0000010: 32b6 0042 3a06 1906 c700 092a b400 323a
0x0000020: 06bb 0007 5919 06b4 0223 1906 b402 2719
0x0000030: 06b4 022a 1906 b402 2d14 022e b702 323a
0x0000040: 07b2 00ba bb02 3459 2ab4 003c 2bb7 0237
0x0000050: 1907 b602 3bb8 028e 1604 6541 1302 ac20
0x0000060: b802 92b1
Stackmap Table:
append_frame(@33,Long,Long,Object[#4])
at com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon.startEvolution(EntityPixelmon.java:497)
at com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution.evolve(Evolution.java:81)
at com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution.handleEvolution(Evolution.java:64)
at com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon.checkEvolution(EntityPixelmon.java:549)
at com.pixelmonmod.pixelmon.entities.pixelmon.stats.Level.tryEvolution(Level.java:329)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.checkEvolution(BattleControllerBase.java:845)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.endBattleWithoutXP(BattleControllerBase.java:837)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.forfeitBattle(BattleControllerBase.java:1039)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.forfeitOrFlee(BattleControllerBase.java:956)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.tryFlee(BattleControllerBase.java:936)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.takeTurn(BattleControllerBase.java:910)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.update(BattleControllerBase.java:352)
at com.pixelmonmod.pixelmon.battles.BattleRegistry.updateBattles(BattleRegistry.java:151)
at com.pixelmonmod.pixelmon.battles.BattleTickHandler.tickStart(BattleTickHandler.java:12)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_36_BattleTickHandler_tickStart_WorldTickEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:635)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:591)
at net.minecraftforge.fml.common.FMLCommonHandler.onPostWorldTick(FMLCommonHandler.java:269)
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:718)
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:387)
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:613)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471)
at java.lang.Thread.run(Thread.java:745)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Thread: Server thread
Stacktrace:
at com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon.startEvolution(EntityPixelmon.java:497)
at com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution.evolve(Evolution.java:81)
at com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution.handleEvolution(Evolution.java:64)
at com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon.checkEvolution(EntityPixelmon.java:549)
at com.pixelmonmod.pixelmon.entities.pixelmon.stats.Level.tryEvolution(Level.java:329)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.checkEvolution(BattleControllerBase.java:845)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.endBattleWithoutXP(BattleControllerBase.java:837)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.forfeitBattle(BattleControllerBase.java:1039)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.forfeitOrFlee(BattleControllerBase.java:956)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.tryFlee(BattleControllerBase.java:936)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.takeTurn(BattleControllerBase.java:910)
at com.pixelmonmod.pixelmon.battles.controller.BattleControllerBase.update(BattleControllerBase.java:352)
at com.pixelmonmod.pixelmon.battles.BattleRegistry.updateBattles(BattleRegistry.java:151)
at com.pixelmonmod.pixelmon.battles.BattleTickHandler.tickStart(BattleTickHandler.java:12)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_36_BattleTickHandler_tickStart_WorldTickEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:635)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:591)
at net.minecraftforge.fml.common.FMLCommonHandler.onPostWorldTick(FMLCommonHandler.java:269)
I decompiled the code that it crashed on; according to the error the most accurate one is this:
private void updateAllAround(final EvolutionStage currentStage) {
EntityLivingBase owner = this.pixelmon.func_70902_q();
if (owner == null) {
owner = (EntityLivingBase)this.pixelmon;
}
final NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(owner.field_71093_bK, owner.field_70165_t, owner.field_70163_u, owner.field_70161_v, 60.0);
Pixelmon.network.sendToAllAround((IMessage)new EvolvePokemon(this.pokemonID, currentStage), point);
}
Outdated
~~After researching the error for some time I found one that seems similar on JavaAssist's JIRA:~~
Please see attached Eclipse project. In the JavassistErrorDemo.java if you run the program with line 64 uncommented, it works. However, including line 64 causes the program to fail with the following stack trace:
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
com/javassist/test/Student$CopyExtractor.getValueList(Ljava/lang/Object;)Ljava/lang/String; @58: invokevirtual
Reason:
Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'com/javassist/test/GradeConverter'
Current Frame:
bci: @58
flags: { }
locals:
{ 'com/javassist/test/Student$CopyExtractor', 'java/lang/Object', 'java/lang/StringBuilder', 'com/javassist/test/Student', 'java/lang/Object' }
stack:
{ 'java/lang/Object', 'com/javassist/test/Grade' }
Bytecode:
0000000: bb00 0c59 b700 104d 2bc0 0012 4e2c 2db6
0000010: 0016 b600 1a57 2c12 1cb6 001a 572c 2db6
0000020: 0020 b600 2357 2c12 1cb6 001a 5712 25b6
0000030: 002b 3a04 1904 2db6 002f b600 3357 2c2d
0000040: b600 2fb6 0036 572c b600 39b0 3a05 bb00
0000050: 3d59 1905 b700 40bf
Exception Handler Table:
bci [0, 76] => handler: 76
Stackmap Table:
same_locals_1_stack_item_extended(@76,Object59)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructor0(Class.java:2964)
at java.lang.Class.newInstance(Class.java:403)
at com.javassist.test.JavassistErrorDemo.makeClass(JavassistErrorDemo.java:83)
at com.javassist.test.JavassistErrorDemo.main(JavassistErrorDemo.java:37)
~~The reply shed some light on my issue:~~
The verification failed because the source code:
com.javassist.test.GradeConverter c2 = com.javassist.test.GradeConverter.class.newInstance();
must be
com.javassist.test.GradeConverter c2 = (com.javassist.test.GradeConverter)com.javassist.test.GradeConverter.class.newInstance();
Note that the cast operator is missing in the original. Although this cast is optional in Java 5 and later, the Javassist compiler assumes the source is in Java 4 (no generics!). This does not mean any performance penalties because the cast is still necessary in Java 8 at bytecode level.
It is a sort of bug that Javassist does not report a type error. This design decision is just for avoiding runtime overhead.
~~So, based on this I figure the issue has to do with the fact that the Object in the code I decompiled is first set to an Entity
(although in this case, it seems to be null) and then is changed to an EntityLivingBase
~~
~~My question is, why would this be an issue when I attach BTrace to the Java application? Without my program attached, the application doesn't crash.~~
bug Core BTRACE