Skip to content

Commit

Permalink
Mimic HotSpot in Class.getEnclosingMethod0.
Browse files Browse the repository at this point in the history
  • Loading branch information
mukel committed Apr 6, 2021
1 parent 036298e commit 4d94a4e
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,21 +565,25 @@ public static boolean isArray(@Host(Class.class) StaticObject self) {
if (enclosingMethodAttr == null) {
return StaticObject.NULL;
}
if (enclosingMethodAttr.getMethodIndex() == 0) {
int classIndex = enclosingMethodAttr.getClassIndex();
if (classIndex == 0) {
return StaticObject.NULL;
}
StaticObject arr = meta.java_lang_Object.allocateReferenceArray(3);
RuntimeConstantPool pool = klass.getConstantPool();
Klass enclosingKlass = pool.resolvedKlassAt(klass, enclosingMethodAttr.getClassIndex());
Klass enclosingKlass = pool.resolvedKlassAt(klass, classIndex);

vm.setArrayObject(enclosingKlass.mirror(), 0, arr);

NameAndTypeConstant nmt = pool.nameAndTypeAt(enclosingMethodAttr.getMethodIndex());
StaticObject name = meta.toGuestString(nmt.getName(pool));
StaticObject desc = meta.toGuestString(nmt.getDescriptor(pool));
int methodIndex = enclosingMethodAttr.getMethodIndex();
if (methodIndex != 0) {
NameAndTypeConstant nmt = pool.nameAndTypeAt(methodIndex);
StaticObject name = meta.toGuestString(nmt.getName(pool));
StaticObject desc = meta.toGuestString(nmt.getDescriptor(pool));

vm.setArrayObject(name, 1, arr);
vm.setArrayObject(desc, 2, arr);
vm.setArrayObject(name, 1, arr);
vm.setArrayObject(desc, 2, arr);
}

return arr;
}
Expand Down

0 comments on commit 4d94a4e

Please sign in to comment.