Skip to content

Commit 1b6df90

Browse files
committed
Statically use LinkResolver to fix type parameters.
1 parent 219b28f commit 1b6df90

File tree

8 files changed

+155
-77
lines changed

8 files changed

+155
-77
lines changed

espresso/src/com.oracle.truffle.espresso.shared/src/com/oracle/truffle/espresso/shared/resolver/LinkResolver.java

Lines changed: 74 additions & 36 deletions
Large diffs are not rendered by default.

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/constantpool/Resolution.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.truffle.espresso.redefinition.ClassRedefinition;
4444
import com.oracle.truffle.espresso.runtime.EspressoContext;
4545
import com.oracle.truffle.espresso.runtime.EspressoException;
46+
import com.oracle.truffle.espresso.runtime.EspressoLinkResolver;
4647
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
4748
import com.oracle.truffle.espresso.shared.JavaKind;
4849
import com.oracle.truffle.espresso.shared.attributes.BootstrapMethodsAttribute;
@@ -66,7 +67,6 @@
6667
import com.oracle.truffle.espresso.shared.descriptors.Symbol.Signature;
6768
import com.oracle.truffle.espresso.shared.descriptors.Symbol.Type;
6869
import com.oracle.truffle.espresso.shared.perf.DebugCounter;
69-
import com.oracle.truffle.espresso.shared.resolver.LinkResolver;
7070
import com.oracle.truffle.espresso.substitutions.JavaType;
7171

7272
public final class Resolution {
@@ -203,18 +203,17 @@ public static Resolvable.ResolvedConstant resolveFieldRefConstant(FieldRefConsta
203203
Symbol<Type> type = thiz.getType(pool);
204204

205205
EspressoContext context = pool.getContext();
206-
LinkResolver<EspressoContext, Klass, Method, Field> resolver = context.getLinkResolver();
207206
Field field;
208207
ClassRedefinition classRedefinition = null;
209208
try {
210209
try {
211-
field = resolver.resolveFieldSymbol(context, accessingKlass, name, type, holderKlass, true, true);
210+
field = EspressoLinkResolver.resolveFieldSymbol(context, accessingKlass, name, type, holderKlass, true, true);
212211
} catch (EspressoException e) {
213212
classRedefinition = context.getClassRedefinition();
214213
if (classRedefinition != null) {
215214
// could be due to ongoing redefinition
216215
classRedefinition.check();
217-
field = resolver.resolveFieldSymbol(context, accessingKlass, name, type, holderKlass, true, true);
216+
field = EspressoLinkResolver.resolveFieldSymbol(context, accessingKlass, name, type, holderKlass, true, true);
218217
} else {
219218
throw e;
220219
}
@@ -357,11 +356,10 @@ public static Resolvable.ResolvedConstant resolveInterfaceMethodRefConstant(Inte
357356

358357
Klass holderInterface = getResolvedHolderKlass(thiz, pool, accessingKlass);
359358
EspressoContext context = pool.getContext();
360-
LinkResolver<EspressoContext, Klass, Method, Field> resolver = context.getLinkResolver();
361359
Symbol<Name> name = thiz.getName(pool);
362360
Symbol<Signature> signature = thiz.getSignature(pool);
363361

364-
Method method = resolver.resolveMethodSymbol(context, accessingKlass, name, signature, holderInterface, true, true, true);
362+
Method method = EspressoLinkResolver.resolveMethodSymbol(context, accessingKlass, name, signature, holderInterface, true, true, true);
365363

366364
return new ResolvedInterfaceMethodRefConstant(method);
367365
}
@@ -478,13 +476,12 @@ public static Resolvable.ResolvedConstant resolveClassMethodRefConstant(ClassMet
478476
METHODREF_RESOLVE_COUNT.inc();
479477

480478
EspressoContext context = pool.getContext();
481-
LinkResolver<EspressoContext, Klass, Method, Field> resolver = context.getLinkResolver();
482479

483480
Klass holderKlass = getResolvedHolderKlass(thiz, pool, accessingKlass);
484481
Symbol<Name> name = thiz.getName(pool);
485482
Symbol<Signature> signature = thiz.getSignature(pool);
486483

487-
Method method = resolver.resolveMethodSymbol(context, accessingKlass, name, signature, holderKlass, false, true, true);
484+
Method method = EspressoLinkResolver.resolveMethodSymbol(context, accessingKlass, name, signature, holderKlass, false, true, true);
488485

489486
if (method.isInvokeIntrinsic()) {
490487
MHInvokeGenericNode.MethodHandleInvoker invoker = MHInvokeGenericNode.linkMethod(context.getMeta().getLanguage(), context.getMeta(), accessingKlass, method, name, signature);

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,20 +1042,6 @@ public final boolean isPrimitive() {
10421042
return this instanceof PrimitiveKlass;
10431043
}
10441044

1045-
public static ObjectKlass asAccessingObjectKlass(Klass k) {
1046-
if (k == null) {
1047-
return null;
1048-
}
1049-
if (k.isPrimitive()) {
1050-
return null;
1051-
}
1052-
if (k.isArray()) {
1053-
return asAccessingObjectKlass(k.getElementalType());
1054-
}
1055-
assert k instanceof ObjectKlass;
1056-
return (ObjectKlass) k;
1057-
}
1058-
10591045
/*
10601046
* The setting of the final bit for types is a bit confusing since arrays are marked as final.
10611047
* This method provides a semantically equivalent test that appropriate for types.
@@ -1582,11 +1568,6 @@ public final Method lookupMethod(Symbol<Name> methodName, Symbol<Signature> sign
15821568
return lookupMethod(methodName, signature, LookupMode.ALL);
15831569
}
15841570

1585-
@Override
1586-
public Method lookupInstanceMethod(Symbol<Name> name, Symbol<Signature> signature) {
1587-
return lookupMethod(name, signature, LookupMode.INSTANCE_ONLY);
1588-
}
1589-
15901571
public final Method vtableLookup(int vtableIndex) {
15911572
if (this instanceof ObjectKlass) {
15921573
return ((ObjectKlass) this).vtableLookupImpl(vtableIndex);
@@ -1913,6 +1894,11 @@ public Method lookupInterfaceMethod(Symbol<Name> name, Symbol<Signature> signatu
19131894
return null;
19141895
}
19151896

1897+
@Override
1898+
public Method lookupInstanceMethod(Symbol<Name> name, Symbol<Signature> signature) {
1899+
return lookupMethod(name, signature, LookupMode.INSTANCE_ONLY);
1900+
}
1901+
19161902
@Idempotent
19171903
@Override
19181904
// Implement here for indempotent, and make sure arrays are not abstract.

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/BytecodeNode.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@
355355
import com.oracle.truffle.espresso.runtime.EspressoContext;
356356
import com.oracle.truffle.espresso.runtime.EspressoException;
357357
import com.oracle.truffle.espresso.runtime.EspressoExitException;
358+
import com.oracle.truffle.espresso.runtime.EspressoLinkResolver;
358359
import com.oracle.truffle.espresso.runtime.GuestAllocator;
359360
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
360-
import com.oracle.truffle.espresso.shared.classfile.ExceptionHandler;
361361
import com.oracle.truffle.espresso.shared.JavaKind;
362362
import com.oracle.truffle.espresso.shared.attributes.BootstrapMethodsAttribute;
363363
import com.oracle.truffle.espresso.shared.attributes.LineNumberTableAttribute;
@@ -366,6 +366,7 @@
366366
import com.oracle.truffle.espresso.shared.bytecode.BytecodeTableSwitch;
367367
import com.oracle.truffle.espresso.shared.bytecode.Bytecodes;
368368
import com.oracle.truffle.espresso.shared.bytecode.VolatileArrayAccess;
369+
import com.oracle.truffle.espresso.shared.classfile.ExceptionHandler;
369370
import com.oracle.truffle.espresso.shared.constantpool.ClassConstant;
370371
import com.oracle.truffle.espresso.shared.constantpool.DoubleConstant;
371372
import com.oracle.truffle.espresso.shared.constantpool.DynamicConstant;
@@ -2411,7 +2412,7 @@ private int quickenArrayStore(final VirtualFrame frame, int top, int curBCI, int
24112412
private InvokeQuickNode dispatchQuickened(int top, int curBCI, char cpi, int opcode, int statementIndex, Method resolutionSeed, boolean allowBytecodeInlining) {
24122413

24132414
Klass symbolicRef = Resolution.getResolvedHolderKlass((MethodRefConstant.Indexes) getConstantPool().methodAt(cpi), getConstantPool(), getDeclaringKlass());
2414-
ResolvedCall<Klass, Method, Field> resolvedCall = getContext().getLinkResolver().resolveCallSite(getContext(),
2415+
ResolvedCall<Klass, Method, Field> resolvedCall = EspressoLinkResolver.resolveCallSite(getContext(),
24152416
getDeclaringKlass(), resolutionSeed, SiteTypes.callSiteFromOpCode(opcode), symbolicRef);
24162417

24172418
Method resolved = resolvedCall.getResolvedMethod();
@@ -2706,7 +2707,7 @@ private int putField(VirtualFrame frame, int top, Field field, int curBCI, int o
27062707
CompilerAsserts.partialEvaluationConstant(field);
27072708
CompilerAsserts.partialEvaluationConstant(mode);
27082709

2709-
getContext().getLinkResolver().resolveFieldAccess(getContext(), getDeclaringKlass(), getMethod(), field, mode);
2710+
EspressoLinkResolver.resolveFieldAccess(getContext(), field, mode, getDeclaringKlass(), getMethod());
27102711

27112712
byte typeHeader = field.getType().byteAt(0);
27122713
int slotCount = (typeHeader == 'J' || typeHeader == 'D') ? 2 : 1;
@@ -2819,7 +2820,7 @@ private int getField(VirtualFrame frame, int top, Field field, int curBCI, int o
28192820

28202821
CompilerAsserts.partialEvaluationConstant(field);
28212822

2822-
getContext().getLinkResolver().resolveFieldAccess(getContext(), getDeclaringKlass(), getMethod(), field, mode);
2823+
EspressoLinkResolver.resolveFieldAccess(getContext(), field, mode, getDeclaringKlass(), getMethod());
28232824

28242825
int slot = top - 1;
28252826
StaticObject receiver;

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/EspressoContext.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
import com.oracle.truffle.espresso.shared.perf.DebugCloseable;
109109
import com.oracle.truffle.espresso.shared.perf.DebugTimer;
110110
import com.oracle.truffle.espresso.shared.perf.TimerCollection;
111-
import com.oracle.truffle.espresso.shared.resolver.LinkResolver;
112111
import com.oracle.truffle.espresso.shared.resolver.meta.ErrorType;
113112
import com.oracle.truffle.espresso.shared.resolver.meta.RuntimeAccess;
114113
import com.oracle.truffle.espresso.substitutions.Substitutions;
@@ -191,7 +190,6 @@ public final class EspressoContext
191190
@CompilationFinal private AgentLibraries agents;
192191
@CompilationFinal private NativeAccess nativeAccess;
193192
@CompilationFinal private JNIHandles handles;
194-
private final LinkResolver<EspressoContext, Klass, Method, Field> linkResolver = new LinkResolver<>();
195193
// endregion VM
196194

197195
@CompilationFinal private EspressoException stackOverflow;
@@ -1258,10 +1256,6 @@ public boolean isJavaBase(ModuleTable.ModuleEntry m) {
12581256

12591257
// RuntimeAccess impl
12601258

1261-
public LinkResolver<EspressoContext, Klass, Method, Field> getLinkResolver() {
1262-
return linkResolver;
1263-
}
1264-
12651259
@Override
12661260
@TruffleBoundary
12671261
public RuntimeException throwError(ErrorType error, String messageFormat, Object... args) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package com.oracle.truffle.espresso.runtime;
25+
26+
import com.oracle.truffle.espresso.impl.Field;
27+
import com.oracle.truffle.espresso.impl.Klass;
28+
import com.oracle.truffle.espresso.impl.Method;
29+
import com.oracle.truffle.espresso.shared.descriptors.Symbol;
30+
import com.oracle.truffle.espresso.shared.resolver.CallSiteType;
31+
import com.oracle.truffle.espresso.shared.resolver.FieldAccessType;
32+
import com.oracle.truffle.espresso.shared.resolver.LinkResolver;
33+
import com.oracle.truffle.espresso.shared.resolver.ResolvedCall;
34+
35+
public final class EspressoLinkResolver {
36+
public static Field resolveFieldSymbol(EspressoContext ctx, Klass accessingKlass,
37+
Symbol<Symbol.Name> name, Symbol<Symbol.Type> type, Klass symbolicHolder,
38+
boolean accessCheck, boolean loadingConstraints) {
39+
return LinkResolver.resolveFieldSymbol(ctx, accessingKlass, name, type, symbolicHolder, accessCheck, loadingConstraints);
40+
}
41+
42+
public static Field resolveFieldAccess(EspressoContext ctx, Field symbolicResolution, FieldAccessType fieldAccessType, Klass currentKlass, Method currentMethod) {
43+
return LinkResolver.resolveFieldAccess(ctx, symbolicResolution, fieldAccessType, currentKlass, currentMethod);
44+
}
45+
46+
public static Method resolveMethodSymbol(EspressoContext ctx, Klass accessingKlass,
47+
Symbol<Symbol.Name> name, Symbol<Symbol.Signature> signature, Klass symbolicHolder,
48+
boolean interfaceLookup,
49+
boolean accessCheck, boolean loadingConstraints) {
50+
return LinkResolver.resolveMethodSymbol(ctx, accessingKlass, name, signature, symbolicHolder, interfaceLookup, accessCheck, loadingConstraints);
51+
}
52+
53+
public static ResolvedCall<Klass, Method, Field> resolveCallSite(EspressoContext ctx, Klass currentKlass, Method symbolicResolution, CallSiteType callSiteType, Klass symbolicHolder) {
54+
return LinkResolver.resolveCallSite(ctx, currentKlass, symbolicResolution, callSiteType, symbolicHolder);
55+
}
56+
57+
private EspressoLinkResolver() {
58+
// no instance.
59+
}
60+
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_java_lang_invoke_MethodHandleNatives.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.oracle.truffle.espresso.nodes.EspressoNode;
7171
import com.oracle.truffle.espresso.runtime.EspressoContext;
7272
import com.oracle.truffle.espresso.runtime.EspressoException;
73+
import com.oracle.truffle.espresso.runtime.EspressoLinkResolver;
7374
import com.oracle.truffle.espresso.runtime.MethodHandleIntrinsics;
7475
import com.oracle.truffle.espresso.runtime.MethodHandleIntrinsics.PolySigIntrinsics;
7576
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
@@ -472,7 +473,7 @@ StaticObject doCached(
472473
// - Static fields are accessed statically
473474
// - Final fields and ref_put*
474475
// These are done when needed by JDK code.
475-
Field f = ctx.getLinkResolver().resolveFieldSymbol(ctx, callerKlass, name, t, resolutionKlass, false, doConstraintsChecks);
476+
Field f = EspressoLinkResolver.resolveFieldSymbol(ctx, callerKlass, name, t, resolutionKlass, false, doConstraintsChecks);
476477
plantResolvedField(memberName, f, refKind, meta, meta.getLanguage());
477478
return memberName;
478479
}
@@ -502,8 +503,8 @@ StaticObject doCached(
502503
}
503504

504505
Symbol<Signature> sig = lookupSignature(meta, desc, mhMethodId);
505-
Method m = ctx.getLinkResolver().resolveMethodSymbol(ctx, callerKlass, name, sig, resolutionKlass, resolutionKlass.isInterface(), doAccessChecks, doConstraintsChecks);
506-
ResolvedCall<Klass, Method, Field> resolvedCall = ctx.getLinkResolver().resolveCallSite(ctx, callerKlass, m, SiteTypes.callSiteFromRefKind(refKind), resolutionKlass);
506+
Method m = EspressoLinkResolver.resolveMethodSymbol(ctx, callerKlass, name, sig, resolutionKlass, resolutionKlass.isInterface(), doAccessChecks, doConstraintsChecks);
507+
ResolvedCall<Klass, Method, Field> resolvedCall = EspressoLinkResolver.resolveCallSite(ctx, callerKlass, m, SiteTypes.callSiteFromRefKind(refKind), resolutionKlass);
507508

508509
plantResolvedMethod(memberName, resolvedCall, meta);
509510

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_sun_reflect_NativeMethodAccessorImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.truffle.espresso.meta.Meta;
3737
import com.oracle.truffle.espresso.nodes.interop.ToEspressoNode;
3838
import com.oracle.truffle.espresso.runtime.EspressoException;
39+
import com.oracle.truffle.espresso.runtime.EspressoLinkResolver;
3940
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
4041
import com.oracle.truffle.espresso.shared.JavaKind;
4142
import com.oracle.truffle.espresso.shared.descriptors.Signatures;
@@ -306,7 +307,7 @@ abstract static class Invoke0 extends SubstitutionNode {
306307
} else {
307308
callSiteType = CallSiteType.Virtual;
308309
}
309-
ResolvedCall<Klass, Method, Field> resolvedCall = meta.getContext().getLinkResolver().resolveCallSite(
310+
ResolvedCall<Klass, Method, Field> resolvedCall = EspressoLinkResolver.resolveCallSite(
310311
meta.getContext(),
311312
null, // No current class.
312313
reflectedMethod, callSiteType, klass);

0 commit comments

Comments
 (0)