use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class VM method getGuestReflectiveConstructorRoot.
@JavaType(java.lang.reflect.Constructor.class)
private static StaticObject getGuestReflectiveConstructorRoot(@JavaType(java.lang.reflect.Constructor.class) StaticObject seed, Meta meta) {
assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Constructor);
StaticObject curConstructor = seed;
Method target = null;
while (target == null) {
target = (Method) meta.HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(curConstructor);
if (target == null) {
curConstructor = meta.java_lang_reflect_Constructor_root.getObject(curConstructor);
}
}
return curConstructor;
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class VM method fillInElement.
private void fillInElement(@JavaType(StackTraceElement.class) StaticObject ste, VM.StackElement element, Method classGetName) {
Method m = element.getMethod();
Klass k = m.getDeclaringKlass();
StaticObject guestClass = k.mirror();
StaticObject loader = k.getDefiningClassLoader();
ModuleEntry module = k.module();
// Fill in class name
getMeta().java_lang_StackTraceElement_declaringClass.setObject(ste, classGetName.invokeDirect(guestClass));
getMeta().java_lang_StackTraceElement_declaringClassObject.setObject(ste, guestClass);
// Fill in loader name
if (!StaticObject.isNull(loader)) {
StaticObject loaderName = getMeta().java_lang_ClassLoader_name.getObject(loader);
if (!StaticObject.isNull(loader)) {
getMeta().java_lang_StackTraceElement_classLoaderName.setObject(ste, loaderName);
}
}
// Fill in method name
Symbol<Name> mname = m.getName();
getMeta().java_lang_StackTraceElement_methodName.setObject(ste, getMeta().toGuestString(mname));
// Fill in module
if (module.isNamed()) {
getMeta().java_lang_StackTraceElement_moduleName.setObject(ste, getMeta().toGuestString(module.getName()));
// TODO: module version
}
// Fill in source information
getMeta().java_lang_StackTraceElement_fileName.setObject(ste, getMeta().toGuestString(m.getSourceFile()));
getMeta().java_lang_StackTraceElement_lineNumber.setInt(ste, m.bciToLineNumber(element.getBCI()));
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class VM method JVM_GetClassDeclaredMethods.
// TODO(tg): inject constructor calltarget.
@VmImpl(isJni = true)
@JavaType(java.lang.reflect.Method[].class)
public StaticObject JVM_GetClassDeclaredMethods(@JavaType(Class.class) StaticObject self, boolean publicOnly) {
Meta meta = getMeta();
ArrayList<Method> collectedMethods = new ArrayList<>();
Klass klass = self.getMirrorKlass();
klass.ensureLinked();
for (Method m : klass.getDeclaredMethods()) {
if ((!publicOnly || m.isPublic()) && // Filter out <init> and <clinit> from reflection.
!Name._init_.equals(m.getName()) && !Name._clinit_.equals(m.getName())) {
collectedMethods.add(m);
}
}
final Method[] methods = collectedMethods.toArray(Method.EMPTY_ARRAY);
return meta.java_lang_reflect_Method.allocateReferenceArray(methods.length, new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int i) {
return methods[i].makeMirror();
}
});
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class Target_sun_reflect_NativeConstructorAccessorImpl method newInstance0.
@Substitution
@JavaType(Object.class)
public static StaticObject newInstance0(@JavaType(Constructor.class) StaticObject constructor, @JavaType(Object[].class) StaticObject args0, @Inject Meta meta) {
Klass klass = meta.java_lang_reflect_Constructor_clazz.getObject(constructor).getMirrorKlass();
klass.safeInitialize();
if (klass.isArray() || klass.isPrimitive() || klass.isInterface() || klass.isAbstract()) {
throw meta.throwException(meta.java_lang_InstantiationException);
}
Method reflectedMethod = Method.getHostReflectiveConstructorRoot(constructor, meta);
StaticObject instance = klass.allocateInstance();
StaticObject parameterTypes = meta.java_lang_reflect_Constructor_parameterTypes.getObject(constructor);
Target_sun_reflect_NativeMethodAccessorImpl.callMethodReflectively(meta, instance, args0, reflectedMethod, klass, parameterTypes);
return instance;
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class EspressoThreadRegistry method unregisterThread.
/**
* Once a thread terminates, remove it from the active set, and notify any thread waiting for VM
* teardown that it should check again for all non-daemon thread completion.
*/
@SuppressFBWarnings(value = "NN", justification = "Removing a thread from the active set is the state change we need.")
public void unregisterThread(StaticObject thread) {
logger.fine(() -> {
String guestName = getThreadAccess().getThreadName(thread);
long guestId = getThreadAccess().getThreadId(thread);
return String.format("unregisterThread([GUEST:%s, %d])", guestName, guestId);
});
activeThreads.remove(thread);
Thread hostThread = getThreadAccess().getHost(thread);
int id = Math.toIntExact(hostThread.getId());
synchronized (activeThreadLock) {
if (id == mainThreadId) {
mainThreadId = -1;
guestMainThread = null;
} else if (id == finalizerThreadId) {
guestFinalizerThread = null;
finalizerThreadId = -1;
} else if (id == referenceHandlerThreadId) {
guestReferenceHandlerThread = null;
referenceHandlerThreadId = -1;
} else {
Object[] threads = guestThreads;
int threadIndex = getThreadIndex(id, threads);
if (getThreadAccess().isAlive(thread)) {
assert threads[threadIndex] == thread;
threads[threadIndex] = null;
} else {
/*
* Non-alive threads may have been removed from guestThreads by
* refactorGuestThreads => threadIndex may be invalid/outdated and the slot
* could be populated by another thread.
*/
if (0 <= threadIndex && threadIndex < threads.length) {
if (threads[threadIndex] == thread) {
threads[threadIndex] = null;
}
}
}
}
}
Object sync = context.getShutdownSynchronizer();
synchronized (sync) {
sync.notifyAll();
}
}
Aggregations