use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class VM method getACCUntil11.
private StaticObject getACCUntil11() {
ArrayList<StaticObject> domains = new ArrayList<>();
final PrivilegedStack stack = getPrivilegedStack();
final boolean[] isPrivileged = new boolean[] { false };
StaticObject context = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<StaticObject>() {
StaticObject prevDomain = StaticObject.NULL;
@Override
public StaticObject visitFrame(FrameInstance frameInstance) {
Method m = getMethodFromFrame(frameInstance);
if (m != null) {
if (stack.compare(frameInstance)) {
isPrivileged[0] = true;
}
StaticObject domain = JVM_GetProtectionDomain(m.getDeclaringKlass().mirror());
if (domain != prevDomain && domain != StaticObject.NULL) {
domains.add(domain);
prevDomain = domain;
}
if (isPrivileged[0]) {
return stack.peekContext();
}
}
return null;
}
});
return getAccFromContext(domains, isPrivileged[0], context);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class VM method getGuestReflectiveConstructorRoot.
@JavaType(java.lang.reflect.Constructor.class)
private static StaticObject getGuestReflectiveConstructorRoot(@JavaType(java.lang.reflect.Constructor.class) StaticObject seed, Meta meta) {
assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Constructor);
StaticObject curConstructor = seed;
Method target = null;
while (target == null) {
target = (Method) meta.HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(curConstructor);
if (target == null) {
curConstructor = meta.java_lang_reflect_Constructor_root.getObject(curConstructor);
}
}
return curConstructor;
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class VM method fillInElement.
private void fillInElement(@JavaType(StackTraceElement.class) StaticObject ste, VM.StackElement element, Method classGetName) {
Method m = element.getMethod();
Klass k = m.getDeclaringKlass();
StaticObject guestClass = k.mirror();
StaticObject loader = k.getDefiningClassLoader();
ModuleEntry module = k.module();
// Fill in class name
getMeta().java_lang_StackTraceElement_declaringClass.setObject(ste, classGetName.invokeDirect(guestClass));
getMeta().java_lang_StackTraceElement_declaringClassObject.setObject(ste, guestClass);
// Fill in loader name
if (!StaticObject.isNull(loader)) {
StaticObject loaderName = getMeta().java_lang_ClassLoader_name.getObject(loader);
if (!StaticObject.isNull(loader)) {
getMeta().java_lang_StackTraceElement_classLoaderName.setObject(ste, loaderName);
}
}
// Fill in method name
Symbol<Name> mname = m.getName();
getMeta().java_lang_StackTraceElement_methodName.setObject(ste, getMeta().toGuestString(mname));
// Fill in module
if (module.isNamed()) {
getMeta().java_lang_StackTraceElement_moduleName.setObject(ste, getMeta().toGuestString(module.getName()));
// TODO: module version
}
// Fill in source information
getMeta().java_lang_StackTraceElement_fileName.setObject(ste, getMeta().toGuestString(m.getSourceFile()));
getMeta().java_lang_StackTraceElement_lineNumber.setInt(ste, m.bciToLineNumber(element.getBCI()));
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class VM method JVM_GetClassDeclaredMethods.
// TODO(tg): inject constructor calltarget.
@VmImpl(isJni = true)
@JavaType(java.lang.reflect.Method[].class)
public StaticObject JVM_GetClassDeclaredMethods(@JavaType(Class.class) StaticObject self, boolean publicOnly) {
Meta meta = getMeta();
ArrayList<Method> collectedMethods = new ArrayList<>();
Klass klass = self.getMirrorKlass();
klass.ensureLinked();
for (Method m : klass.getDeclaredMethods()) {
if ((!publicOnly || m.isPublic()) && // Filter out <init> and <clinit> from reflection.
!Name._init_.equals(m.getName()) && !Name._clinit_.equals(m.getName())) {
collectedMethods.add(m);
}
}
final Method[] methods = collectedMethods.toArray(Method.EMPTY_ARRAY);
return meta.java_lang_reflect_Method.allocateReferenceArray(methods.length, new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int i) {
return methods[i].makeMirror();
}
});
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class Target_sun_reflect_NativeConstructorAccessorImpl method newInstance0.
@Substitution
@JavaType(Object.class)
public static StaticObject newInstance0(@JavaType(Constructor.class) StaticObject constructor, @JavaType(Object[].class) StaticObject args0, @Inject Meta meta) {
Klass klass = meta.java_lang_reflect_Constructor_clazz.getObject(constructor).getMirrorKlass();
klass.safeInitialize();
if (klass.isArray() || klass.isPrimitive() || klass.isInterface() || klass.isAbstract()) {
throw meta.throwException(meta.java_lang_InstantiationException);
}
Method reflectedMethod = Method.getHostReflectiveConstructorRoot(constructor, meta);
StaticObject instance = klass.allocateInstance();
StaticObject parameterTypes = meta.java_lang_reflect_Constructor_parameterTypes.getObject(constructor);
Target_sun_reflect_NativeMethodAccessorImpl.callMethodReflectively(meta, instance, args0, reflectedMethod, klass, parameterTypes);
return instance;
}
Aggregations