use of com.oracle.truffle.espresso.substitutions.JavaType 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.substitutions.JavaType in project graal by oracle.
the class VM method JVM_GetStackTraceElement.
@VmImpl(isJni = true)
@JavaType(StackTraceElement.class)
public StaticObject JVM_GetStackTraceElement(@JavaType(Throwable.class) StaticObject self, int index, @Inject SubstitutionProfiler profiler) {
Meta meta = getMeta();
if (index < 0) {
profiler.profile(0);
throw meta.throwException(meta.java_lang_IndexOutOfBoundsException);
}
StaticObject ste = meta.java_lang_StackTraceElement.allocateInstance();
StackTrace frames = EspressoException.getFrames(self, meta);
if (frames == null || index >= frames.size) {
profiler.profile(1);
throw meta.throwException(meta.java_lang_IndexOutOfBoundsException);
}
StackElement stackElement = frames.trace[index];
Method method = stackElement.getMethod();
if (method == null) {
return StaticObject.NULL;
}
int bci = stackElement.getBCI();
getMeta().java_lang_StackTraceElement_init.invokeDirect(/* this */
ste, /* declaringClass */
meta.toGuestString(MetaUtil.internalNameToJava(method.getDeclaringKlass().getType().toString(), true, true)), /* methodName */
meta.toGuestString(method.getName()), /* fileName */
meta.toGuestString(method.getSourceFile()), /* lineNumber */
method.bciToLineNumber(bci));
return ste;
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method JVM_GetProperties.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(String[].class)
public StaticObject JVM_GetProperties() {
Map<String, String> props = buildPropertiesMap();
StaticObject array = getMeta().java_lang_String.allocateReferenceArray(props.size() * 2);
int index = 0;
for (Map.Entry<String, String> entry : props.entrySet()) {
getInterpreterToVM().setArrayObject(getMeta().toGuestString(entry.getKey()), index * 2, array);
getInterpreterToVM().setArrayObject(getMeta().toGuestString(entry.getValue()), index * 2 + 1, array);
index++;
}
return array;
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method JVM_GetSystemPackages.
@VmImpl(isJni = true)
@JavaType(String[].class)
public StaticObject JVM_GetSystemPackages() {
String[] packages = getRegistries().getBootClassRegistry().getPackages();
StaticObject[] array = new StaticObject[packages.length];
for (int i = 0; i < packages.length; i++) {
array[i] = getMeta().toGuestString(packages[i]);
}
return StaticObject.createArray(getMeta().java_lang_String.getArrayClass(), array);
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method JVM_InitClassName.
@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_InitClassName(@JavaType(Class.class) StaticObject self) {
StaticObject name = JVM_GetClassName(self);
getMeta().java_lang_Class_name.set(self, name);
return name;
}
Aggregations