use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class VM method JVM_DoPrivileged.
@VmImpl(isJni = true)
@SuppressWarnings("unused")
@JavaType(Object.class)
public StaticObject JVM_DoPrivileged(@JavaType(Class.class) StaticObject cls, /* PrivilegedAction or PrivilegedActionException */
@JavaType(Object.class) StaticObject action, @JavaType(AccessControlContext.class) StaticObject context, boolean wrapException, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
if (StaticObject.isNull(action)) {
profiler.profile(0);
throw meta.throwNullPointerException();
}
FrameInstance callerFrame = getCallerFrame(1, false, meta);
assert callerFrame != null : "No caller ?";
Klass caller = getMethodFromFrame(callerFrame).getDeclaringKlass();
StaticObject acc = context;
if (!StaticObject.isNull(context)) {
if (!isAuthorized(context, caller)) {
acc = createDummyACC();
}
}
Method run = action.getKlass().lookupMethod(Name.run, Signature.Object);
if (run == null || !run.isPublic() || run.isStatic()) {
profiler.profile(1);
throw meta.throwException(meta.java_lang_InternalError);
}
// Prepare the privileged stack
PrivilegedStack stack = getPrivilegedStack();
stack.push(callerFrame, acc, caller);
// Execute the action.
StaticObject result;
try {
result = (StaticObject) run.invokeDirect(action);
} catch (EspressoException e) {
profiler.profile(2);
if (meta.java_lang_Exception.isAssignableFrom(e.getGuestException().getKlass()) && !meta.java_lang_RuntimeException.isAssignableFrom(e.getGuestException().getKlass())) {
profiler.profile(3);
StaticObject wrapper = meta.java_security_PrivilegedActionException.allocateInstance();
getMeta().java_security_PrivilegedActionException_init_Exception.invokeDirect(wrapper, e.getGuestException());
throw meta.throwException(wrapper);
}
profiler.profile(4);
throw e;
} finally {
stack.pop();
}
return result;
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class VM method JVM_GetSimpleBinaryName.
@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_GetSimpleBinaryName(@JavaType(Class.class) StaticObject self) {
Klass k = self.getMirrorKlass();
if (k.isPrimitive() || k.isArray()) {
return StaticObject.NULL;
}
ObjectKlass klass = (ObjectKlass) k;
RuntimeConstantPool pool = klass.getConstantPool();
InnerClassesAttribute inner = klass.getInnerClasses();
for (InnerClassesAttribute.Entry entry : inner.entries()) {
int innerClassIndex = entry.innerClassIndex;
if (innerClassIndex != 0) {
if (pool.classAt(innerClassIndex).getName(pool) == klass.getName()) {
if (pool.resolvedKlassAt(k, innerClassIndex) == k) {
if (entry.innerNameIndex != 0) {
Symbol<Name> innerName = pool.symbolAt(entry.innerNameIndex);
return getMeta().toGuestString(innerName);
} else {
break;
}
}
}
}
}
return StaticObject.NULL;
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class VM method JVM_GetDeclaringClass.
@VmImpl(isJni = true)
@JavaType(Class.class)
public static StaticObject JVM_GetDeclaringClass(@JavaType(Class.class) StaticObject self) {
// Primitives and arrays are not "enclosed".
if (!(self.getMirrorKlass() instanceof ObjectKlass)) {
return StaticObject.NULL;
}
ObjectKlass k = (ObjectKlass) self.getMirrorKlass();
Klass outerKlass = computeEnclosingClass(k);
if (outerKlass == null) {
return StaticObject.NULL;
}
return outerKlass.mirror();
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class VM method JVM_GetClassInterfaces.
@VmImpl(isJni = true)
@JavaType(Class[].class)
public StaticObject JVM_GetClassInterfaces(@JavaType(Class.class) StaticObject self) {
final Klass[] superInterfaces = self.getMirrorKlass().getImplementedInterfaces();
StaticObject instance = getMeta().java_lang_Class.allocateReferenceArray(superInterfaces.length, new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int i) {
return superInterfaces[i].mirror();
}
});
return instance;
}
use of com.oracle.truffle.espresso.impl.Klass 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()));
}
Aggregations