use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.
the class Substitutions method registerStaticSubstitution.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void registerStaticSubstitution(JavaSubstitution.Factory substitutorFactory) {
List<Symbol<Type>> parameterTypes = new ArrayList<>();
for (int i = substitutorFactory.hasReceiver() ? 1 : 0; i < substitutorFactory.parameterTypes().length; i++) {
String type = substitutorFactory.parameterTypes()[i];
parameterTypes.add(StaticSymbols.putType(type));
}
Symbol<Type> returnType = StaticSymbols.putType(substitutorFactory.returnType());
Symbol<Signature> signature = StaticSymbols.putSignature(returnType, parameterTypes.toArray(Symbol.EMPTY_ARRAY));
EspressoRootNodeFactory factory = new EspressoRootNodeFactory() {
@Override
public EspressoRootNode createNodeIfValid(Method methodToSubstitute, boolean forceValid) {
if (!substitutorFactory.isValidFor(methodToSubstitute.getJavaVersion())) {
return null;
}
StaticObject classLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
if (forceValid || ClassRegistry.loaderIsBootOrPlatform(classLoader, methodToSubstitute.getMeta())) {
return EspressoRootNode.create(null, new IntrinsicSubstitutorNode(substitutorFactory, methodToSubstitute));
}
getLogger().warning(new Supplier<String>() {
@Override
public String get() {
StaticObject givenLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
return "Static substitution for " + methodToSubstitute + " does not apply.\n" + "\tExpected class loader: Boot (null) or platform class loader\n" + "\tGiven class loader: " + EspressoInterop.toDisplayString(givenLoader, false) + "\n";
}
});
return null;
}
};
String[] classNames = substitutorFactory.substitutionClassNames();
String[] methodNames = substitutorFactory.getMethodNames();
for (int i = 0; i < classNames.length; i++) {
assert classNames[i].startsWith("Target_");
Symbol<Type> classType = StaticSymbols.putType("L" + classNames[i].substring("Target_".length()).replace('_', '/') + ";");
Symbol<Name> methodName = StaticSymbols.putName(methodNames[i]);
registerStaticSubstitution(classType, methodName, signature, factory, true);
}
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.
the class VM method JVM_FindLoadedClass.
@VmImpl(isJni = true)
@JavaType(Class.class)
public StaticObject JVM_FindLoadedClass(@JavaType(ClassLoader.class) StaticObject loader, @JavaType(String.class) StaticObject name) {
Symbol<Type> type = getTypes().fromClassGetName(getMeta().toHostString(name));
// HotSpot skips reflection (DelegatingClassLoader) class loaders.
Klass klass = getRegistries().findLoadedClass(type, nonReflectionClassLoader(loader));
if (klass == null) {
return StaticObject.NULL;
}
return klass.mirror();
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.
the class VM method JVM_DefineClass.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_DefineClass(@Pointer TruffleObject namePtr, @JavaType(ClassLoader.class) StaticObject loader, @Pointer TruffleObject bufPtr, int len, @JavaType(ProtectionDomain.class) StaticObject pd) {
ByteBuffer buf = NativeUtils.directByteBuffer(bufPtr, len, JavaKind.Byte);
final byte[] bytes = new byte[len];
buf.get(bytes);
// can be null
Symbol<Type> type = namePtrToInternal(namePtr);
StaticObject clazz = getContext().getRegistries().defineKlass(type, bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd)).mirror();
assert clazz != null;
return clazz;
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Type 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.descriptors.Symbol.Type 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();
}
Aggregations