use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class VM method JVM_GetDeclaredClasses.
@VmImpl(isJni = true)
@JavaType(Class[].class)
public StaticObject JVM_GetDeclaredClasses(@JavaType(Class.class) StaticObject self) {
Meta meta = getMeta();
Klass klass = self.getMirrorKlass();
if (klass.isPrimitive() || klass.isArray()) {
return meta.java_lang_Class.allocateReferenceArray(0);
}
ObjectKlass instanceKlass = (ObjectKlass) klass;
InnerClassesAttribute innerClasses = (InnerClassesAttribute) instanceKlass.getAttribute(InnerClassesAttribute.NAME);
if (innerClasses == null || innerClasses.entries().length == 0) {
return meta.java_lang_Class.allocateReferenceArray(0);
}
RuntimeConstantPool pool = instanceKlass.getConstantPool();
List<Klass> innerKlasses = new ArrayList<>();
for (InnerClassesAttribute.Entry entry : innerClasses.entries()) {
if (entry.innerClassIndex != 0 && entry.outerClassIndex != 0) {
// Check to see if the name matches the class we're looking for
// before attempting to find the class.
Symbol<Name> outerDescriptor = pool.classAt(entry.outerClassIndex).getName(pool);
// Check decriptors/names before resolving.
if (outerDescriptor.equals(instanceKlass.getName())) {
Klass outerKlass = pool.resolvedKlassAt(instanceKlass, entry.outerClassIndex);
if (outerKlass == instanceKlass) {
Klass innerKlass = pool.resolvedKlassAt(instanceKlass, entry.innerClassIndex);
// HotSpot:
// Throws an exception if outer klass has not declared k as
// an inner klass
// Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
// TODO(peterssen): The check in HotSpot is redundant.
innerKlasses.add(innerKlass);
}
}
}
}
return meta.java_lang_Class.allocateReferenceArray(innerKlasses.size(), new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int index) {
return innerKlasses.get(index).mirror();
}
});
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class VM method JVM_ClassDepth.
@VmImpl(isJni = true)
@TruffleBoundary
public int JVM_ClassDepth(@JavaType(String.class) StaticObject name) {
Symbol<Name> className = getContext().getNames().lookup(getMeta().toHostString(name).replace('.', '/'));
if (className == null) {
return -1;
}
Integer res = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Integer>() {
int depth = 0;
@Override
public Integer visitFrame(FrameInstance frameInstance) {
Method m = getMethodFromFrame(frameInstance);
if (m != null) {
if (className.equals(m.getDeclaringKlass().getName())) {
return depth;
}
depth++;
}
return null;
}
});
return res == null ? -1 : res;
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class VM method defineModule.
@SuppressWarnings("try")
public void defineModule(StaticObject module, String moduleName, boolean is_open, String[] packages, SubstitutionProfiler profiler) {
Meta meta = getMeta();
StaticObject loader = meta.java_lang_Module_loader.getObject(module);
if (loader != nonReflectionClassLoader(loader)) {
profiler.profile(15);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader is an invalid delegating class loader");
}
// Prepare variables
ClassRegistry registry = getRegistries().getClassRegistry(loader);
assert registry != null;
PackageTable packageTable = registry.packages();
ModuleTable moduleTable = registry.modules();
assert moduleTable != null && packageTable != null;
boolean loaderIsBootOrPlatform = ClassRegistry.loaderIsBootOrPlatform(loader, meta);
ArrayList<Symbol<Name>> pkgSymbols = new ArrayList<>();
try (EntryTable.BlockLock block = packageTable.write()) {
for (String str : packages) {
// Extract the package symbols. Also checks for duplicates.
if (!loaderIsBootOrPlatform && (str.equals("java") || str.startsWith("java/"))) {
// Only modules defined to either the boot or platform class loader, can define
// a "java/" package.
profiler.profile(14);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, cat("Class loader (", loader.getKlass().getType(), ") tried to define prohibited package name: ", str));
}
Symbol<Name> symbol = getNames().getOrCreate(str);
if (packageTable.lookup(symbol) != null) {
profiler.profile(13);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, cat("Package ", str, " is already defined."));
}
pkgSymbols.add(symbol);
}
Symbol<Name> moduleSymbol = getNames().getOrCreate(moduleName);
// Try define module
ModuleEntry moduleEntry = moduleTable.createAndAddEntry(moduleSymbol, registry, is_open, module);
if (moduleEntry == null) {
// Module already defined
profiler.profile(12);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, cat("Module ", moduleName, " is already defined"));
}
// Register packages
for (Symbol<Name> pkgSymbol : pkgSymbols) {
PackageEntry pkgEntry = packageTable.createAndAddEntry(pkgSymbol, moduleEntry);
// should have been checked before
assert pkgEntry != null;
}
// Link guest module to its host representation
meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, moduleEntry);
}
if (StaticObject.isNull(loader) && getContext().getVmProperties().bootClassPathType().isExplodedModule()) {
profiler.profile(11);
// If we have an exploded build, and the module is defined to the bootloader, prepend a
// class path entry for this module.
prependModuleClasspath(moduleName);
}
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class JniEnv method GetStaticFieldID.
/**
* <h3>jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
* </h3>
* <p>
* Returns the field ID for a static field of a class. The field is specified by its name and
* signature. The GetStatic<type>Field and SetStatic<type>Field families of accessor functions
* use field IDs to retrieve static fields.
* <p>
* GetStaticFieldID() causes an uninitialized class to be initialized.
*
* @param clazz a Java class object.
* @param namePtr the static field name in a 0-terminated modified UTF-8 string.
* @param typePtr the field signature in a 0-terminated modified UTF-8 string.
* @return a field ID, or NULL if the specified static field cannot be found.
* @throws NoSuchFieldError if the specified static field cannot be found.
* @throws ExceptionInInitializerError if the class initializer fails due to an exception.
* @throws OutOfMemoryError if the system runs out of memory.
*/
@JniImpl
@Handle(Field.class)
public long GetStaticFieldID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject typePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
String type = NativeUtils.interopPointerToString(typePtr);
assert name != null && type != null;
Field field = null;
Symbol<Name> fieldName = getNames().lookup(name);
if (fieldName != null) {
Symbol<Type> fieldType = getTypes().lookup(type);
if (fieldType != null) {
Klass klass = clazz.getMirrorKlass();
klass.safeInitialize();
// Lookup only if name and type are known symbols.
field = klass.lookupField(fieldName, fieldType, Klass.LookupMode.STATIC_ONLY);
assert field == null || field.getType().equals(fieldType);
}
}
if (field == null || !field.isStatic()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, name);
}
return fieldIds.handlify(field);
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class JniEnv method GetStaticMethodID.
/**
* <h3>jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char
* *sig);</h3>
* <p>
* Returns the method ID for a static method of a class. The method is specified by its name and
* signature.
* <p>
* GetStaticMethodID() causes an uninitialized class to be initialized.
*
* @param clazz a Java class object.
* @param namePtr the static method name in a 0-terminated modified UTF-8 string.
* @param signaturePtr the method signature in a 0-terminated modified UTF-8 string.
* @return a method ID, or NULL if the operation fails.
* @throws NoSuchMethodError if the specified static method cannot be found. *
* @throws ExceptionInInitializerError if the class initializer fails due to an exception.
* @throws OutOfMemoryError if the system runs out of memory.
*/
@JniImpl
@Handle(Method.class)
public long GetStaticMethodID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject signaturePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
String signature = NativeUtils.interopPointerToString(signaturePtr);
assert name != null && signature != null;
Method method = null;
Symbol<Name> methodName = getNames().lookup(name);
if (methodName != null) {
Symbol<Signature> methodSignature = getSignatures().lookupValidSignature(signature);
if (methodSignature != null) {
// Throw a NoSuchMethodError exception if we have an instance of a
// primitive java.lang.Class
Klass klass = clazz.getMirrorKlass();
if (klass.isPrimitive()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
}
klass.safeInitialize();
// Lookup only if name and type are known symbols.
if (Name._clinit_.equals(methodName)) {
// Never search superclasses for static initializers.
method = klass.lookupDeclaredMethod(methodName, methodSignature);
} else {
method = klass.lookupMethod(methodName, methodSignature);
}
}
}
if (method == null || !method.isStatic()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
}
return methodIds.handlify(method);
}
Aggregations