use of com.oracle.truffle.espresso.substitutions.JavaType 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.substitutions.JavaType in project graal by oracle.
the class VM method JVM_GetArrayElement.
/**
* Returns the value of the indexed component in the specified array object. The value is
* automatically wrapped in an object if it has a primitive type.
*
* @param array the array
* @param index the index
* @throws NullPointerException If the specified object is null
* @throws IllegalArgumentException If the specified object is not an array
* @throws ArrayIndexOutOfBoundsException If the specified {@code index} argument is negative,
* or if it is greater than or equal to the length of the specified array
* @return the (possibly wrapped) value of the indexed component in the specified array
*/
@VmImpl(isJni = true)
@JavaType(Object.class)
public StaticObject JVM_GetArrayElement(@JavaType(Object.class) StaticObject array, int index, @Inject SubstitutionProfiler profiler) {
Meta meta = getMeta();
if (StaticObject.isNull(array)) {
profiler.profile(7);
throw meta.throwNullPointerException();
}
if (array.isArray()) {
profiler.profile(6);
return getInterpreterToVM().getArrayObject(index, array);
}
if (!array.getClass().isArray()) {
profiler.profile(5);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Argument is not an array");
}
assert array.getClass().isArray() && array.getClass().getComponentType().isPrimitive();
if (index < 0 || index >= JVM_GetArrayLength(array, profiler)) {
profiler.profile(4);
throw meta.throwExceptionWithMessage(meta.java_lang_ArrayIndexOutOfBoundsException, "index");
}
Object elem = Array.get(array, index);
return getMeta().boxPrimitive(elem);
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method JVM_GetCallerClass.
@VmImpl(isJni = true)
@JavaType(Class.class)
public StaticObject JVM_GetCallerClass(int depth, @Inject SubstitutionProfiler profiler) {
// temporarily for existing code to use until a replacement API is defined.
if (depth != JVM_CALLER_DEPTH) {
FrameInstance callerFrame = getCallerFrame(depth, true, getMeta());
if (callerFrame != null) {
Method callerMethod = getMethodFromFrame(callerFrame);
if (callerMethod != null) {
return callerMethod.getDeclaringKlass().mirror();
}
}
// Not found.
return StaticObject.NULL;
}
// Getting the class of the caller frame.
//
// The call stack at this point looks something like this:
//
// [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
// [1] [ @CallerSensitive API.method ]
// [.] [ (skipped intermediate frames) ]
// [n] [ caller ]
Meta meta = getMeta();
StaticObject[] exception = new StaticObject[] { null };
Method callerMethod = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Method>() {
private int depth = 0;
@SuppressWarnings("fallthrough")
@Override
public Method visitFrame(FrameInstance frameInstance) {
Method method = getMethodFromFrame(frameInstance);
if (method != null) {
switch(depth) {
case 0:
// Reflection.getCallerClass.
if (method != meta.sun_reflect_Reflection_getCallerClass) {
exception[0] = Meta.initExceptionWithMessage(meta.java_lang_InternalError, "JVM_GetCallerClass must only be called from Reflection.getCallerClass");
return /* ignore */
method;
}
// fall-through
case 1:
// Frame 0 and 1 must be caller sensitive.
if (!method.isCallerSensitive()) {
exception[0] = Meta.initExceptionWithMessage(meta.java_lang_InternalError, "CallerSensitive annotation expected at frame " + depth);
return /* ignore */
method;
}
break;
default:
if (!isIgnoredBySecurityStackWalk(method, meta)) {
return method;
}
}
++depth;
}
return null;
}
});
// InternalError was recorded.
StaticObject internalError = exception[0];
if (internalError != null) {
profiler.profile(0);
assert InterpreterToVM.instanceOf(internalError, meta.java_lang_InternalError);
throw meta.throwException(internalError);
}
if (callerMethod == null) {
return StaticObject.NULL;
}
return callerMethod.getDeclaringKlass().mirror();
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class Management method GetMemoryUsage.
@ManagementImpl
@JavaType(Object.class)
public StaticObject GetMemoryUsage(@SuppressWarnings("unused") boolean heap) {
Method init = getMeta().java_lang_management_MemoryUsage.lookupDeclaredMethod(Symbol.Name._init_, getSignatures().makeRaw(Symbol.Type._void, Symbol.Type._long, Symbol.Type._long, Symbol.Type._long, Symbol.Type._long));
StaticObject instance = getMeta().java_lang_management_MemoryUsage.allocateInstance();
init.invokeDirect(instance, 0L, 0L, 0L, 0L);
return instance;
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method getGuestReflectiveMethodRoot.
// endregion stack inspection
// region annotations
@JavaType(java.lang.reflect.Method.class)
private static StaticObject getGuestReflectiveMethodRoot(@JavaType(java.lang.reflect.Method.class) StaticObject seed, Meta meta) {
assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Method);
StaticObject curMethod = seed;
Method target = null;
while (target == null) {
target = (Method) meta.HIDDEN_METHOD_KEY.getHiddenObject(curMethod);
if (target == null) {
curMethod = meta.java_lang_reflect_Method_root.getObject(curMethod);
}
}
return curMethod;
}
Aggregations