use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class VM method JVM_FindClassFromCaller.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_FindClassFromCaller(@Pointer TruffleObject namePtr, boolean init, @JavaType(ClassLoader.class) StaticObject loader, @JavaType(Class.class) StaticObject caller) {
Meta meta = getMeta();
Symbol<Type> type = namePtrToInternal(namePtr);
Klass result;
if (Types.isPrimitive(type)) {
result = null;
} else {
StaticObject protectionDomain;
// manager to avoid the performance cost of getting the calling class.
if (!StaticObject.isNull(caller) && !StaticObject.isNull(loader)) {
protectionDomain = JVM_GetProtectionDomain(caller);
} else {
protectionDomain = StaticObject.NULL;
}
result = meta.resolveSymbolOrNull(type, loader, protectionDomain);
}
if (result == null) {
throw meta.throwExceptionWithMessage(meta.java_lang_ClassNotFoundException, NativeUtils.interopPointerToString(namePtr));
}
if (init) {
result.safeInitialize();
}
return result.mirror();
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class VM method JVM_FindClassFromBootLoader.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_FindClassFromBootLoader(@Pointer TruffleObject namePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
if (name == null) {
return StaticObject.NULL;
}
String internalName = name;
if (!name.startsWith("[")) {
// Force 'L' type.
internalName = "L" + name + ";";
}
if (!Validation.validTypeDescriptor(ByteSequence.create(internalName), false)) {
return StaticObject.NULL;
}
Symbol<Type> type = getTypes().fromClassGetName(internalName);
if (Types.isPrimitive(type)) {
return StaticObject.NULL;
}
Klass klass = getMeta().resolveSymbolOrNull(type, StaticObject.NULL, StaticObject.NULL);
if (klass == null) {
return StaticObject.NULL;
}
return klass.mirror();
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class BytecodeNode method resolveExceptionHandlers.
@ExplodeLoop
@SuppressWarnings("unused")
private ExceptionHandler resolveExceptionHandlers(int bci, StaticObject ex) {
CompilerAsserts.partialEvaluationConstant(bci);
ExceptionHandler[] handlers = getMethodVersion().getExceptionHandlers();
ExceptionHandler resolved = null;
for (ExceptionHandler toCheck : handlers) {
if (bci >= toCheck.getStartBCI() && bci < toCheck.getEndBCI()) {
Klass catchType = null;
if (!toCheck.isCatchAll()) {
// exception handlers are similar to instanceof bytecodes, so we pass instanceof
catchType = resolveType(Bytecodes.INSTANCEOF, (char) toCheck.catchTypeCPI());
}
if (catchType == null || InterpreterToVM.instanceOf(ex, catchType)) {
// the first found exception handler is our exception handler
resolved = toCheck;
break;
}
}
}
return resolved;
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class BytecodeNode method putPoolConstant.
private void putPoolConstant(VirtualFrame frame, int top, char cpi, int opcode) {
assert opcode == LDC || opcode == LDC_W || opcode == LDC2_W;
RuntimeConstantPool pool = getConstantPool();
PoolConstant constant = pool.at(cpi);
if (constant instanceof IntegerConstant) {
assert opcode == LDC || opcode == LDC_W;
putInt(frame, top, ((IntegerConstant) constant).value());
} else if (constant instanceof LongConstant) {
assert opcode == LDC2_W;
putLong(frame, top, ((LongConstant) constant).value());
} else if (constant instanceof DoubleConstant) {
assert opcode == LDC2_W;
putDouble(frame, top, ((DoubleConstant) constant).value());
} else if (constant instanceof FloatConstant) {
assert opcode == LDC || opcode == LDC_W;
putFloat(frame, top, ((FloatConstant) constant).value());
} else if (constant instanceof StringConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject internedString = pool.resolvedStringAt(cpi);
putObject(frame, top, internedString);
} else if (constant instanceof ClassConstant) {
assert opcode == LDC || opcode == LDC_W;
Klass klass = pool.resolvedKlassAt(getDeclaringKlass(), cpi);
putObject(frame, top, klass.mirror());
} else if (constant instanceof MethodHandleConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject methodHandle = pool.resolvedMethodHandleAt(getDeclaringKlass(), cpi);
putObject(frame, top, methodHandle);
} else if (constant instanceof MethodTypeConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject methodType = pool.resolvedMethodTypeAt(getDeclaringKlass(), cpi);
putObject(frame, top, methodType);
} else if (constant instanceof DynamicConstant) {
DynamicConstant.Resolved dynamicConstant = pool.resolvedDynamicConstantAt(getDeclaringKlass(), cpi);
dynamicConstant.putResolved(frame, top, this);
} else {
CompilerDirectives.transferToInterpreter();
throw EspressoError.unimplemented(constant.toString());
}
}
use of com.oracle.truffle.espresso.impl.Klass in project graal by oracle.
the class JniEnv method UnregisterNatives.
/**
* <h3>jint UnregisterNatives(JNIEnv *env, jclass clazz);</h3>
* <p>
* Unregisters native methods of a class. The class goes back to the state before it was linked
* or registered with its native method functions.
* <p>
* This function should not be used in normal native code. Instead, it provides special programs
* a way to reload and relink native libraries.
*
* @param clazz a Java class object.
* <p>
* Returns 0 on success; returns a negative value on failure.
*/
@JniImpl
@TruffleBoundary
public int UnregisterNatives(@JavaType(Class.class) StaticObject clazz) {
Klass klass = clazz.getMirrorKlass();
for (Method m : klass.getDeclaredMethods()) {
if (m.isNative()) {
getSubstitutions().removeRuntimeSubstitution(m);
m.unregisterNative();
}
}
return JNI_OK;
}
Aggregations