use of com.oracle.truffle.espresso.meta.Meta 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.meta.Meta in project graal by oracle.
the class ClassRedefinition method handleRemovedMethod.
/**
* @param accessingKlass the receiver's klass when the method is not static, resolutionSeed's
* declaring klass otherwise
*/
@TruffleBoundary
public Method handleRemovedMethod(Method resolutionSeed, Klass accessingKlass) {
// wait for potential ongoing redefinition to complete
check();
Method replacementMethod = accessingKlass.lookupMethod(resolutionSeed.getName(), resolutionSeed.getRawSignature(), accessingKlass);
Meta meta = resolutionSeed.getMeta();
if (replacementMethod == null) {
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, meta.toGuestString(resolutionSeed.getDeclaringKlass().getNameAsString() + "." + resolutionSeed.getName() + resolutionSeed.getRawSignature()) + " was removed by class redefinition");
} else if (resolutionSeed.isStatic() != replacementMethod.isStatic()) {
String message = resolutionSeed.isStatic() ? "expected static method: " : "expected non-static method:" + replacementMethod.getName();
throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, message);
} else {
// Update to the latest version of the replacement method
return replacementMethod;
}
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class StaticObject method toVerboseString.
@TruffleBoundary
public final String toVerboseString() {
if (this == NULL) {
return "null";
}
if (isForeignObject()) {
return String.format("foreign object: %s\n%s", getKlass().getTypeAsString(), InteropLibrary.getUncached().toDisplayString(rawForeignObject()));
}
if (getKlass() == getKlass().getMeta().java_lang_String) {
Meta meta = getKlass().getMeta();
StaticObject value = meta.java_lang_String_value.getObject(this);
if (value == null || isNull(value)) {
// Prevents debugger crashes when trying to inspect a string in construction.
return "<UNINITIALIZED>";
}
return Meta.toHostStringStatic(this);
}
if (isArray()) {
return unwrap().toString();
}
if (getKlass() == getKlass().getMeta().java_lang_Class) {
return "mirror: " + getMirrorKlass().toString();
}
StringBuilder str = new StringBuilder(getKlass().getType().toString());
for (Field f : ((ObjectKlass) getKlass()).getFieldTable()) {
// Also prints hidden fields
if (!f.isRemoved()) {
str.append("\n ").append(f.getName()).append(": ").append(f.get(this).toString());
}
}
return str.toString();
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class EspressoContext method spawnVM.
@SuppressWarnings("try")
private void spawnVM() {
try (DebugCloseable spawn = SPAWN_VM.scope(timers)) {
long initStartTimeNanos = System.nanoTime();
this.nativeAccess = spawnNativeAccess();
initVmProperties();
// Spawn JNI first, then the VM.
try (DebugCloseable vmInit = VM_INIT.scope(timers)) {
// Mokapot is loaded
this.vm = VM.create(getJNI());
vm.attachThread(Thread.currentThread());
}
if (getJavaVersion().modulesEnabled()) {
registries.initJavaBaseModule();
registries.getBootClassRegistry().initUnnamedModule(StaticObject.NULL);
}
// TODO: link libjimage
initializeAgents();
try (DebugCloseable metaInit = META_INIT.scope(timers)) {
this.meta = new Meta(this);
}
this.metaInitialized = true;
this.threads = new ThreadsAccess(meta);
this.blockingSupport = BlockingSupport.create(threads);
this.interpreterToVM = new InterpreterToVM(this);
try (DebugCloseable knownClassInit = KNOWN_CLASS_INIT.scope(timers)) {
initializeKnownClass(Type.java_lang_Object);
for (Symbol<Type> type : Arrays.asList(Type.java_lang_String, Type.java_lang_System, // JDK-8069005
Type.java_lang_Class, Type.java_lang_ThreadGroup, Type.java_lang_Thread)) {
initializeKnownClass(type);
}
}
if (meta.jdk_internal_misc_UnsafeConstants != null) {
initializeKnownClass(Type.jdk_internal_misc_UnsafeConstants);
UnsafeAccess.initializeGuestUnsafeConstants(meta);
}
// Create main thread as soon as Thread class is initialized.
threadRegistry.createMainThread(meta);
try (DebugCloseable knownClassInit = KNOWN_CLASS_INIT.scope(timers)) {
initializeKnownClass(Type.java_lang_Object);
for (Symbol<Type> type : Arrays.asList(Type.java_lang_reflect_Method, Type.java_lang_ref_Finalizer)) {
initializeKnownClass(type);
}
}
referenceDrainer.initReferenceDrain();
try (DebugCloseable systemInit = SYSTEM_INIT.scope(timers)) {
// Call guest initialization
if (getJavaVersion().java8OrEarlier()) {
meta.java_lang_System_initializeSystemClass.invokeDirect(null);
} else {
assert getJavaVersion().java9OrLater();
meta.java_lang_System_initPhase1.invokeDirect(null);
int e = (int) meta.java_lang_System_initPhase2.invokeDirect(null, false, false);
if (e != 0) {
throw EspressoError.shouldNotReachHere();
}
getVM().getJvmti().postVmStart();
modulesInitialized = true;
meta.java_lang_System_initPhase3.invokeDirect(null);
}
}
getVM().getJvmti().postVmInit();
meta.postSystemInit();
try (DebugCloseable knownClassInit = KNOWN_CLASS_INIT.scope(timers)) {
// System exceptions.
for (Symbol<Type> type : Arrays.asList(Type.java_lang_OutOfMemoryError, Type.java_lang_NullPointerException, Type.java_lang_ClassCastException, Type.java_lang_ArrayStoreException, Type.java_lang_ArithmeticException, Type.java_lang_StackOverflowError, Type.java_lang_IllegalMonitorStateException, Type.java_lang_IllegalArgumentException)) {
initializeKnownClass(type);
}
}
// Init memoryError instances
StaticObject stackOverflowErrorInstance = meta.java_lang_StackOverflowError.allocateInstance();
StaticObject outOfMemoryErrorInstance = meta.java_lang_OutOfMemoryError.allocateInstance();
// Preemptively set stack trace.
meta.HIDDEN_FRAMES.setHiddenObject(stackOverflowErrorInstance, VM.StackTrace.EMPTY_STACK_TRACE);
meta.java_lang_Throwable_backtrace.setObject(stackOverflowErrorInstance, stackOverflowErrorInstance);
meta.HIDDEN_FRAMES.setHiddenObject(outOfMemoryErrorInstance, VM.StackTrace.EMPTY_STACK_TRACE);
meta.java_lang_Throwable_backtrace.setObject(outOfMemoryErrorInstance, outOfMemoryErrorInstance);
this.stackOverflow = EspressoException.wrap(stackOverflowErrorInstance, meta);
this.outOfMemory = EspressoException.wrap(outOfMemoryErrorInstance, meta);
meta.java_lang_StackOverflowError.lookupDeclaredMethod(Name._init_, Signature._void_String).invokeDirect(stackOverflowErrorInstance, meta.toGuestString("VM StackOverFlow"));
meta.java_lang_OutOfMemoryError.lookupDeclaredMethod(Name._init_, Signature._void_String).invokeDirect(outOfMemoryErrorInstance, meta.toGuestString("VM OutOfMemory"));
// Create application (system) class loader.
StaticObject systemClassLoader = null;
try (DebugCloseable systemLoader = SYSTEM_CLASSLOADER.scope(timers)) {
systemClassLoader = (StaticObject) meta.java_lang_ClassLoader_getSystemClassLoader.invokeDirect(null);
}
topBindings = new EspressoBindings(systemClassLoader, getEnv().getOptions().get(EspressoOptions.ExposeNativeJavaVM));
initDoneTimeNanos = System.nanoTime();
long elapsedNanos = initDoneTimeNanos - initStartTimeNanos;
getLogger().log(Level.FINE, "VM booted in {0} ms", TimeUnit.NANOSECONDS.toMillis(elapsedNanos));
}
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class EspressoReferenceDrainer method initReferenceDrain.
void initReferenceDrain() {
TruffleLanguage.Env env = getContext().getEnv();
Meta meta = getMeta();
if (getContext().multiThreadingEnabled()) {
if (getJavaVersion().java8OrEarlier()) {
// Initialize reference queue
this.hostToGuestReferenceDrainThread = env.createThread(new ReferenceDrain() {
@SuppressWarnings("rawtypes")
@Override
protected void updateReferencePendingList(EspressoReference head, EspressoReference prev, StaticObject lock) {
StaticObject obj = meta.java_lang_ref_Reference_pending.getAndSetObject(meta.java_lang_ref_Reference.getStatics(), head.getGuestReference());
meta.java_lang_ref_Reference_discovered.set(prev.getGuestReference(), obj);
getVM().JVM_MonitorNotify(lock, profiler);
}
});
} else if (getJavaVersion().java9OrLater()) {
// Initialize reference queue
this.hostToGuestReferenceDrainThread = env.createThread(new ReferenceDrain() {
@SuppressWarnings("rawtypes")
@Override
protected void updateReferencePendingList(EspressoReference head, EspressoReference prev, StaticObject lock) {
EspressoLock pLock = getLock();
pLock.lock();
try {
StaticObject obj = referencePendingList;
referencePendingList = head.getGuestReference();
meta.java_lang_ref_Reference_discovered.set(prev.getGuestReference(), obj);
getVM().JVM_MonitorNotify(lock, profiler);
pLock.signalAll();
} finally {
pLock.unlock();
}
}
});
} else {
throw EspressoError.shouldNotReachHere();
}
}
if (hostToGuestReferenceDrainThread != null) {
hostToGuestReferenceDrainThread.setName("Reference Drain");
}
}
Aggregations