use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class MHLinkToNode method call.
@Override
public Object call(Object[] args) {
assert (getMethod().isStatic());
Method.MethodVersion resolutionSeed = getTarget(args);
Object[] basicArgs = unbasic(args, resolutionSeed.getMethod().getParsedSignature(), 0, argCount - 1, hasReceiver);
// method might have been redefined or removed by redefinition
if (!resolutionSeed.getRedefineAssumption().isValid()) {
if (resolutionSeed.getMethod().isRemovedByRedefition()) {
Klass receiverKlass = hasReceiver ? ((StaticObject) basicArgs[0]).getKlass() : resolutionSeed.getMethod().getDeclaringKlass();
resolutionSeed = resolutionSeed.getMethod().getContext().getClassRedefinition().handleRemovedMethod(resolutionSeed.getMethod(), receiverKlass).getMethodVersion();
}
}
Method target = linker.linkTo(resolutionSeed.getMethod(), args);
Object result = executeCall(basicArgs, target.getMethodVersion());
return rebasic(result, target.getReturnKind());
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class Substitutions method registerStaticSubstitution.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void registerStaticSubstitution(JavaSubstitution.Factory substitutorFactory) {
List<Symbol<Type>> parameterTypes = new ArrayList<>();
for (int i = substitutorFactory.hasReceiver() ? 1 : 0; i < substitutorFactory.parameterTypes().length; i++) {
String type = substitutorFactory.parameterTypes()[i];
parameterTypes.add(StaticSymbols.putType(type));
}
Symbol<Type> returnType = StaticSymbols.putType(substitutorFactory.returnType());
Symbol<Signature> signature = StaticSymbols.putSignature(returnType, parameterTypes.toArray(Symbol.EMPTY_ARRAY));
EspressoRootNodeFactory factory = new EspressoRootNodeFactory() {
@Override
public EspressoRootNode createNodeIfValid(Method methodToSubstitute, boolean forceValid) {
if (!substitutorFactory.isValidFor(methodToSubstitute.getJavaVersion())) {
return null;
}
StaticObject classLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
if (forceValid || ClassRegistry.loaderIsBootOrPlatform(classLoader, methodToSubstitute.getMeta())) {
return EspressoRootNode.create(null, new IntrinsicSubstitutorNode(substitutorFactory, methodToSubstitute));
}
getLogger().warning(new Supplier<String>() {
@Override
public String get() {
StaticObject givenLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
return "Static substitution for " + methodToSubstitute + " does not apply.\n" + "\tExpected class loader: Boot (null) or platform class loader\n" + "\tGiven class loader: " + EspressoInterop.toDisplayString(givenLoader, false) + "\n";
}
});
return null;
}
};
String[] classNames = substitutorFactory.substitutionClassNames();
String[] methodNames = substitutorFactory.getMethodNames();
for (int i = 0; i < classNames.length; i++) {
assert classNames[i].startsWith("Target_");
Symbol<Type> classType = StaticSymbols.putType("L" + classNames[i].substring("Target_".length()).replace('_', '/') + ";");
Symbol<Name> methodName = StaticSymbols.putName(methodNames[i]);
registerStaticSubstitution(classType, methodName, signature, factory, true);
}
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class Target_java_lang_invoke_MethodHandleNatives method plantInvokeBasic.
// region MemberName planting
private static void plantInvokeBasic(StaticObject memberName, Klass resolutionKlass, Symbol<Name> name, Symbol<Signature> sig, Klass callerKlass, int refKind, Meta meta) {
assert (name == Name.invokeBasic);
Method target = resolutionKlass.lookupMethod(name, sig, callerKlass);
meta.HIDDEN_VMTARGET.setHiddenObject(memberName, target);
meta.java_lang_invoke_MemberName_flags.setInt(memberName, getMethodFlags(target, refKind));
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class Target_java_lang_invoke_MethodHandleNatives method plantMethodMemberName.
private static void plantMethodMemberName(StaticObject memberName, Klass resolutionKlass, Symbol<Name> name, Symbol<Signature> sig, int refKind, Klass callerKlass, boolean accessCheck, boolean constraintsChecks, Meta meta) {
Method target = resolutionKlass.lookupMethod(name, sig, callerKlass);
if (target == null) {
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, cat("Failed lookup for method ", resolutionKlass.getName(), "#", name, ":", sig));
}
if (target.isStatic() != (refKind == REF_invokeStatic)) {
String expected = (refKind == REF_invokeStatic) ? "Static" : "Instance";
String actual = (refKind == REF_invokeStatic) ? "Instance" : "Static";
throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, cat(expected, " method lookup resulted in ", actual, " resolution for method ", resolutionKlass.getName(), "#", name, ":", sig));
}
if (accessCheck) {
MemberRefConstant.doAccessCheck(callerKlass, target.getDeclaringKlass(), target, meta);
}
if (constraintsChecks) {
target.checkLoadingConstraints(callerKlass.getDefiningClassLoader(), resolutionKlass.getDefiningClassLoader());
}
plantResolvedMethod(memberName, target, refKind, meta);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class EspressoInterop method asInstant.
@ExportMessage
@TruffleBoundary
static Instant asInstant(StaticObject receiver, @CachedLibrary("receiver") InteropLibrary receiverLibrary, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (receiverLibrary.isInstant(receiver)) {
StaticObject instant;
Meta meta = receiver.getKlass().getMeta();
if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
instant = (StaticObject) meta.java_time_ZonedDateTime_toInstant.invokeDirect(receiver);
} else if (instanceOf(receiver, meta.java_util_Date)) {
int index = meta.java_util_Date_toInstant.getVTableIndex();
Method virtualToInstant = receiver.getKlass().vtableLookup(index);
instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
} else {
instant = receiver;
}
assert instanceOf(instant, meta.java_time_Instant);
long seconds = (long) meta.java_time_Instant_seconds.get(instant);
int nanos = (int) meta.java_time_Instant_nanos.get(instant);
return Instant.ofEpochSecond(seconds, nanos);
}
error.enter();
throw UnsupportedMessageException.create();
}
Aggregations