Skip to content

Commit 2c18cce

Browse files
Fix flags when instantiating polymorphic signature methods
In particular the resulting method shouldn't have the VARARGS flag.
1 parent 1eea300 commit 2c18cce

File tree

1 file changed

+22
-7
lines changed
  • espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl

1 file changed

+22
-7
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Method.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
import static com.oracle.truffle.espresso.bytecode.Bytecodes.PUTSTATIC;
3030
import static com.oracle.truffle.espresso.bytecode.Bytecodes.RETURN;
3131
import static com.oracle.truffle.espresso.classfile.Constants.ACC_CALLER_SENSITIVE;
32+
import static com.oracle.truffle.espresso.classfile.Constants.ACC_FINAL;
3233
import static com.oracle.truffle.espresso.classfile.Constants.ACC_FORCE_INLINE;
3334
import static com.oracle.truffle.espresso.classfile.Constants.ACC_HIDDEN;
3435
import static com.oracle.truffle.espresso.classfile.Constants.ACC_NATIVE;
3536
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SCOPED;
37+
import static com.oracle.truffle.espresso.classfile.Constants.ACC_STATIC;
38+
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SYNTHETIC;
3639
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VARARGS;
3740
import static com.oracle.truffle.espresso.classfile.Constants.REF_invokeInterface;
3841
import static com.oracle.truffle.espresso.classfile.Constants.REF_invokeSpecial;
@@ -128,9 +131,8 @@ public final class Method extends Member<Signature> implements TruffleObject, Co
128131
private final Method proxy;
129132
private String genericSignature;
130133

131-
// always null unless the raw signature exposed for this method should be
132-
// different from the one in the linkedKlass
133134
private final Symbol<Signature> rawSignature;
135+
private final int rawFlags;
134136

135137
// the parts of the method that can change when it's redefined
136138
// are encapsulated within the methodVersion
@@ -148,6 +150,7 @@ public final class Method extends Member<Signature> implements TruffleObject, Co
148150

149151
private Method(Method method, CodeAttribute split) {
150152
this.rawSignature = method.rawSignature;
153+
this.rawFlags = method.rawFlags;
151154
this.declaringKlass = method.declaringKlass;
152155
this.methodVersion = new MethodVersion(method.getMethodVersion().klassVersion, method.getRuntimeConstantPool(), method.getLinkedMethod(),
153156
method.getMethodVersion().poisonPill, split);
@@ -166,12 +169,13 @@ private Method(Method method, CodeAttribute split) {
166169
}
167170

168171
Method(ObjectKlass.KlassVersion klassVersion, LinkedMethod linkedMethod, RuntimeConstantPool pool) {
169-
this(klassVersion, linkedMethod, linkedMethod.getRawSignature(), pool);
172+
this(klassVersion, linkedMethod, linkedMethod.getRawSignature(), pool, linkedMethod.getFlags());
170173
}
171174

172-
Method(ObjectKlass.KlassVersion klassVersion, LinkedMethod linkedMethod, Symbol<Signature> rawSignature, RuntimeConstantPool pool) {
175+
Method(ObjectKlass.KlassVersion klassVersion, LinkedMethod linkedMethod, Symbol<Signature> rawSignature, RuntimeConstantPool pool, int rawFlags) {
173176
this.declaringKlass = klassVersion.getKlass();
174177
this.rawSignature = rawSignature;
178+
this.rawFlags = rawFlags;
175179
this.methodVersion = new MethodVersion(klassVersion, pool, linkedMethod, false, (CodeAttribute) linkedMethod.getAttribute(CodeAttribute.NAME));
176180

177181
try {
@@ -522,7 +526,7 @@ public boolean isClassInitializer() {
522526

523527
@Override
524528
public int getModifiers() {
525-
return getMethodVersion().getModifiers();
529+
return rawFlags;
526530
}
527531

528532
public boolean isCallerSensitive() {
@@ -813,7 +817,18 @@ public int getCatchLocation(int bci, StaticObject ex) {
813817
// Spawns a placeholder method for MH intrinsics
814818
public Method createIntrinsic(Symbol<Signature> polymorphicRawSignature) {
815819
assert isPolySignatureIntrinsic();
816-
return new Method(declaringKlass.getKlassVersion(), getLinkedMethod(), polymorphicRawSignature, getRuntimeConstantPool());
820+
int flags;
821+
MethodHandleIntrinsics.PolySigIntrinsics iid = MethodHandleIntrinsics.getId(this);
822+
if (iid == MethodHandleIntrinsics.PolySigIntrinsics.InvokeGeneric) {
823+
flags = getModifiers() & ~ACC_VARARGS;
824+
} else {
825+
flags = ACC_NATIVE | ACC_SYNTHETIC | ACC_FINAL;
826+
if (iid.isStaticPolymorphicSignature()) {
827+
flags |= ACC_STATIC;
828+
}
829+
}
830+
assert Modifier.isNative(flags);
831+
return new Method(declaringKlass.getKlassVersion(), getLinkedMethod(), polymorphicRawSignature, getRuntimeConstantPool(), flags);
817832
}
818833

819834
public MethodHandleIntrinsicNode spawnIntrinsicNode(EspressoLanguage language, Meta meta, ObjectKlass accessingKlass, Symbol<Name> mname, Symbol<Signature> signature) {
@@ -1547,7 +1562,7 @@ public String getGenericSignatureAsString() {
15471562

15481563
@Override
15491564
public int getModifiers() {
1550-
return linkedMethod.getFlags();
1565+
return getMethod().getModifiers();
15511566
}
15521567

15531568
@Override

0 commit comments

Comments
 (0)