use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class ThreadsAccess method callInterrupt.
/**
* Lookups and calls the guest Thread.interrupt() method.
*/
public void callInterrupt(StaticObject guestThread) {
assert guestThread != null && getMeta().java_lang_Thread.isAssignableFrom(guestThread.getKlass());
// Thread.interrupt is non-final.
Method interruptMethod = guestThread.getKlass().vtableLookup(getMeta().java_lang_Thread_interrupt.getVTableIndex());
assert interruptMethod != null;
interruptMethod.invokeDirect(guestThread);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class Target_sun_reflect_NativeMethodAccessorImpl method invoke0.
/**
* Invokes the underlying method represented by this {@code Method} object, on the specified
* object with the specified parameters. Individual parameters are automatically unwrapped to
* match primitive formal parameters, and both primitive and reference parameters are subject to
* method invocation conversions as necessary.
*
* <p>
* If the underlying method is static, then the specified {@code receiver} argument is ignored.
* It may be null.
*
* <p>
* If the number of formal parameters required by the underlying method is 0, the supplied
* {@code args} array may be of length 0 or null.
*
* <p>
* If the underlying method is an instance method, it is invoked using dynamic method lookup as
* documented in The Java Language Specification, Second Edition, section 15.12.4.4; in
* particular, overriding based on the runtime type of the target object will occur.
*
* <p>
* If the underlying method is static, the class that declared the method is initialized if it
* has not already been initialized.
*
* <p>
* If the method completes normally, the value it returns is returned to the caller of invoke;
* if the value has a primitive type, it is first appropriately wrapped in an object. However,
* if the value has the type of an array of a primitive type, the elements of the array are
* <i>not</i> wrapped in objects; in other words, an array of primitive type is returned. If the
* underlying method return type is void, the invocation returns null.
*
* @param receiver the object the underlying method is invoked from
* @param args the arguments used for the method call
* @return the result of dispatching the method represented by this object on {@code receiver}
* with parameters {@code args}
*
* IllegalAccessException if this {@code Method} object is enforcing Java language
* access control and the underlying method is inaccessible.
*
* IllegalArgumentException if the method is an instance method and the specified object
* argument is not an instance of the class or interface declaring the underlying method
* (or of a subclass or implementor thereof); if the number of actual and formal
* parameters differ; if an unwrapping conversion for primitive arguments fails; or if,
* after possible unwrapping, a parameter value cannot be converted to the corresponding
* formal parameter type by a method invocation conversion. // @exception
* InvocationTargetException if the underlying method throws an exception.
*
* NullPointerException if the specified object is null and the method is an instance
* method. exception ExceptionInInitializerError if the initialization provoked by this
* method fails.
*/
@Substitution
@JavaType(Object.class)
public static StaticObject invoke0(@JavaType(java.lang.reflect.Method.class) StaticObject guestMethod, @JavaType(Object.class) StaticObject receiver, @JavaType(Object[].class) StaticObject args, @Inject Meta meta) {
StaticObject curMethod = guestMethod;
Method reflectedMethod = null;
while (reflectedMethod == null) {
reflectedMethod = (Method) meta.HIDDEN_METHOD_KEY.getHiddenObject(curMethod);
if (reflectedMethod == null) {
curMethod = meta.java_lang_reflect_Method_root.getObject(curMethod);
}
}
Klass klass = meta.java_lang_reflect_Method_clazz.getObject(guestMethod).getMirrorKlass();
if (klass == meta.java_lang_invoke_MethodHandle && (reflectedMethod.getName() == Name.invoke || reflectedMethod.getName() == Name.invokeExact)) {
StaticObject cause = Meta.initExceptionWithMessage(meta.java_lang_UnsupportedOperationException, "Cannot reflectively invoke MethodHandle.{invoke,invokeExact}");
StaticObject invocationTargetException = Meta.initExceptionWithCause(meta.java_lang_reflect_InvocationTargetException, cause);
throw meta.throwException(invocationTargetException);
}
StaticObject parameterTypes = meta.java_lang_reflect_Method_parameterTypes.getObject(guestMethod);
StaticObject result = callMethodReflectively(meta, receiver, args, reflectedMethod, klass, parameterTypes);
return result;
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class ClassInfo method create.
public static ImmutableClassInfo create(Klass klass, InnerClassRedefiner innerClassRedefiner) {
StringBuilder hierarchy = new StringBuilder();
StringBuilder methods = new StringBuilder();
StringBuilder fields = new StringBuilder();
StringBuilder enclosing = new StringBuilder();
Symbol<Name> name = klass.getName();
Matcher matcher = InnerClassRedefiner.ANON_INNER_CLASS_PATTERN.matcher(name.toString());
if (matcher.matches()) {
// fingerprints are only relevant for inner classes
hierarchy.append(klass.getSuperClass().getTypeAsString()).append(";");
for (Klass itf : klass.getImplementedInterfaces()) {
hierarchy.append(itf.getTypeAsString()).append(";");
}
for (Method method : klass.getDeclaredMethods()) {
methods.append(method.getNameAsString()).append(";");
methods.append(method.getSignatureAsString()).append(";");
}
for (Field field : klass.getDeclaredFields()) {
fields.append(field.getTypeAsString()).append(";");
fields.append(field.getNameAsString()).append(";");
}
ObjectKlass objectKlass = (ObjectKlass) klass;
ConstantPool pool = klass.getConstantPool();
NameAndTypeConstant nmt = pool.nameAndTypeAt(objectKlass.getEnclosingMethod().getMethodIndex());
enclosing.append(nmt.getName(pool)).append(";").append(nmt.getDescriptor(pool));
}
// find all currently loaded direct inner classes and create class infos
ArrayList<ImmutableClassInfo> inners = new ArrayList<>(1);
Set<ObjectKlass> loadedInnerClasses = innerClassRedefiner.findLoadedInnerClasses(klass);
for (Klass inner : loadedInnerClasses) {
matcher = InnerClassRedefiner.ANON_INNER_CLASS_PATTERN.matcher(inner.getNameAsString());
// only add anonymous inner classes
if (matcher.matches()) {
inners.add(innerClassRedefiner.getGlobalClassInfo(inner));
}
}
return new ImmutableClassInfo((ObjectKlass) klass, name, klass.getDefiningClassLoader(), hierarchy.toString(), methods.toString(), fields.toString(), enclosing.toString(), inners, null);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class ClassRedefinition method handleRemovedMethod.
/**
* @param accessingKlass the receiver's klass when the method is not static, resolutionSeed's
* declaring klass otherwise
*/
@TruffleBoundary
public Method handleRemovedMethod(Method resolutionSeed, Klass accessingKlass) {
// wait for potential ongoing redefinition to complete
check();
Method replacementMethod = accessingKlass.lookupMethod(resolutionSeed.getName(), resolutionSeed.getRawSignature(), accessingKlass);
Meta meta = resolutionSeed.getMeta();
if (replacementMethod == null) {
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, meta.toGuestString(resolutionSeed.getDeclaringKlass().getNameAsString() + "." + resolutionSeed.getName() + resolutionSeed.getRawSignature()) + " was removed by class redefinition");
} else if (resolutionSeed.isStatic() != replacementMethod.isStatic()) {
String message = resolutionSeed.isStatic() ? "expected static method: " : "expected non-static method:" + replacementMethod.getName();
throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, message);
} else {
// Update to the latest version of the replacement method
return replacementMethod;
}
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class MHInvokeBasicNode method call.
@Override
public Object call(Object[] args) {
StaticObject mh = (StaticObject) args[0];
StaticObject lform = form.getObject(mh);
StaticObject mname = vmentry.getObject(lform);
Method target = (Method) hiddenVmtarget.getHiddenObject(mname);
return executeCall(args, target);
}
Aggregations