Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a broken StackMapTable. #831

Merged
merged 1 commit into from
Jan 27, 2021
Merged

Fixed a broken StackMapTable. #831

merged 1 commit into from
Jan 27, 2021

Conversation

tuchida
Copy link
Contributor

@tuchida tuchida commented Jan 27, 2021

Before the fix, I got this error when I ran the test.

org.mozilla.javascript.classfile.tests.ClassFileWriterTest > testStackMapTable FAILED
    java.lang.VerifyError: Inconsistent stackmap frames at branch target 34
    Exception Details:
      Location:
        TestStackMapTable.returnObject()Ljava/lang/Object; @34: aload_0
      Reason:
        Type 'java/math/BigInteger' (current frame, stack[0]) is not assignable to 'TestStackMapTable' (stack map, stack[0])
      Current Frame:
        bci: @27
        flags: { }
        locals: { '[Z' }
        stack: { 'java/math/BigInteger' }
      Stackmap Frame:
        bci: @34
        flags: { }
        locals: { '[Z' }
        stack: { 'TestStackMapTable' }
      Bytecode:
        0x0000000: b800 164b bb00 0959 04bc 0859 0310 7b54
        0x0000010: b700 0d59 c700 0a2a 0304 54a7 0007 2a04
        0x0000020: 0454 2a05 0454 b0                      
      Stackmap Table:
        full_frame(@30,{Object[#24]},{Object[#9]})
        same_locals_1_stack_item_frame(@34,Object[#2])
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at org.mozilla.javascript.classfile.tests.ClassFileWriterTest.testStackMapTable(ClassFileWriterTest.java:55)

if (tag == TypeInfo.UNINITIALIZED_VARIABLE(0) ||
tag == TypeInfo.UNINITIALIZED_THIS) {
if ("<init>".equals(methodName)) {
int newType =
TypeInfo.OBJECT(itsThisClassIndex);
initializeTypeInfo(instType, newType);

UNINITIALIZED_THIS

example:

// constructor
public TestClass() {
    super();

It is correct to rewrite the UNINITIALIZED_THIS type with this.getClass() in this case.

UNINITIALIZED_VARIABLE(0)

example:

    o = new BigInteger(bytes);

It is probably correct to rewrite it with BigInteger instead of this.getClass() in this case.

I'm not familiar with Java bytecode, so could you please check if the pull request is correct?

@gbrail
Copy link
Collaborator

gbrail commented Jan 27, 2021

I'm all for fixing bugs at this layer and also having unit tests for it. Thanks!

@gbrail gbrail merged commit 70b9f49 into mozilla:master Jan 27, 2021
@tuchida tuchida deleted the broken-StackMapTable branch February 10, 2021 11:50
@p-bakker p-bakker added the bug Issues considered a bug label Oct 13, 2021
@p-bakker p-bakker added this to the Release 1.7.14 milestone Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues considered a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants