ASM (from ObjectWeb) not calculating MaxStack correctly even though ClassWriter( COMPUTE_MAX + COMPUTE_STACK ) is set

本小妞迷上赌 提交于 2020-01-05 04:31:06

问题


I am getting expected ClassVerifyErrors when attempting to load a class i have generated using ASM. On further inspection i can see that the jvm is correct and that the method is talking about has an invalid MAX_STACK value. THe strange thing is am using the auto calculate the stack and max local options so this should not be a problem... The method with the invalid option is very simple and yet the result is bad bytecode.

I have written a class with the intended method and compared my asm generated class against what javac produces and the byte codes matchup with the only error being the max stack is 0 which is wrong while javac sets a value of 2.

Id like to avoid having to calculate tha max stack/locals myself.


回答1:


Max stack and variable calculation can produce the wrong results if bytecode is not valid. You can verify that by running generated code trough the CheckClassAdapter.

For example,

  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
  // generate code into cw instance...

  PrintWriter pw = new PrintWriter(System.out);
  CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), true, pw);


来源:https://stackoverflow.com/questions/2235493/asm-from-objectweb-not-calculating-maxstack-correctly-even-though-classwriter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!