use of com.oracle.truffle.espresso.substitutions.JavaType 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.substitutions.JavaType in project graal by oracle.
the class VM method JVM_AssertionStatusDirectives.
// endregion array
// region assertion
/**
* Espresso only supports basic -ea and -esa options. Complex per-class/package filters are
* unsupported.
*/
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(internalName = "Ljava/lang/AssertionStatusDirectives;")
public StaticObject JVM_AssertionStatusDirectives(@SuppressWarnings("unused") @JavaType(Class.class) StaticObject unused) {
Meta meta = getMeta();
StaticObject instance = meta.java_lang_AssertionStatusDirectives.allocateInstance();
meta.java_lang_AssertionStatusDirectives.lookupMethod(Name._init_, Signature._void).invokeDirect(instance);
meta.java_lang_AssertionStatusDirectives_classes.set(instance, meta.java_lang_String.allocateReferenceArray(0));
meta.java_lang_AssertionStatusDirectives_classEnabled.set(instance, meta._boolean.allocatePrimitiveArray(0));
meta.java_lang_AssertionStatusDirectives_packages.set(instance, meta.java_lang_String.allocateReferenceArray(0));
meta.java_lang_AssertionStatusDirectives_packageEnabled.set(instance, meta._boolean.allocatePrimitiveArray(0));
boolean ea = getContext().getEnv().getOptions().get(EspressoOptions.EnableAssertions);
meta.java_lang_AssertionStatusDirectives_deflt.set(instance, ea);
return instance;
}
use of com.oracle.truffle.espresso.substitutions.JavaType 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.substitutions.JavaType in project graal by oracle.
the class VM method JVM_InitProperties.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Properties.class)
public StaticObject JVM_InitProperties(@JavaType(Properties.class) StaticObject properties) {
Map<String, String> props = buildPropertiesMap();
Method setProperty = properties.getKlass().lookupMethod(Name.setProperty, Signature.Object_String_String);
for (Map.Entry<String, String> entry : props.entrySet()) {
setProperty.invokeWithConversions(properties, entry.getKey(), entry.getValue());
}
return properties;
}
use of com.oracle.truffle.espresso.substitutions.JavaType 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();
}
Aggregations