Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.qbicc.interpreter;
import java.lang.invoke.MethodHandles;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.function.Consumer;
import org.qbicc.context.ClassContext;
import org.qbicc.context.CompilationContext;
import org.qbicc.graph.literal.Literal;
import org.qbicc.type.ClassObjectType;
import org.qbicc.type.Primitive;
import org.qbicc.type.ValueType;
import org.qbicc.type.definition.DefinedTypeDefinition;
import org.qbicc.type.definition.element.ConstructorElement;
import org.qbicc.type.definition.element.ExecutableElement;
import org.qbicc.type.definition.element.MethodElement;
import io.smallrye.common.constraint.Assert;
import org.qbicc.type.descriptor.MethodDescriptor;
import org.qbicc.type.descriptor.TypeDescriptor;
import org.qbicc.type.methodhandle.MethodHandleConstant;
/**
* A virtual machine.
*/
public interface Vm {
/**
* Get the related compilation context.
*
* @return the related compilation context
*/
CompilationContext getCompilationContext();
/**
* Perform VM initialization in the currently attached thread.
*/
void initialize();
/**
* Perform second-stage VM initialization in the currently attached thread.
*/
void initialize2();
/**
* Create a new thread.
*
* @param threadName the thread name
* @param threadGroup the thread group object (or {@code null})
* @param daemon {@code true} to make a daemon thread
* @return the new thread
*/
VmThread newThread(String threadName, VmObject threadGroup, boolean daemon, int priority);
/**
* Perform the given action with the given thread attached to the host thread. Any previously attached thread is
* suspended.
*
* @param thread the thread to attach (must not be {@code null})
* @param action the action to perform (must not be {@code null})
*/
default void doAttached(VmThread thread, Runnable action) {
Assert.checkNotNullParam("thread", thread);
Assert.checkNotNullParam("action", action);
VmThread old = VmPrivate.CURRENT_THREAD.get();
VmPrivate.CURRENT_THREAD.set(thread);
try {
action.run();
} finally {
if (old == null) {
VmPrivate.CURRENT_THREAD.remove();
} else {
VmPrivate.CURRENT_THREAD.set(old);
}
}
}
static VmThread currentThread() {
return VmPrivate.CURRENT_THREAD.get();
}
static VmThread requireCurrentThread() {
VmThread vmThread = currentThread();
if (vmThread == null) {
throw new IllegalStateException("Thread is not attached");
}
return vmThread;
}
static Vm current() {
return requireCurrentThread().getVM();
}
static Vm requireCurrent() {
Vm current = current();
if (current == null) {
throw new IllegalStateException("JavaVM is not attached");
}
return current;
}
/**
* Load a class. If the class is already loaded, it is returned without entering the VM. Otherwise the
* current thread must be bound to a VM thread.
*
* @param classContext the class context instance (must not be {@code null})
* @param name the internal name of the class to load (must not be {@code null})
* @return the class (not {@code null})
* @throws Thrown if the internal JVM has thrown an exception while loading the class
*/
DefinedTypeDefinition loadClass(ClassContext classContext, String name) throws Thrown;
/**
* Load a resource. Resources are not cached. The current thread must be bound to a VM thread.
*
* @param classContext the class context instance (must not be {@code null})
* @param name the resource name (must not be {@code null})
* @return the resource bytes, or {@code null} if it is not found
* @throws Thrown if the internal JVM has thrown an exception while loading the resource
*/
byte[] loadResource(ClassContext classContext, String name) throws Thrown;
/**
* Load all resources with the given name. Resources are not cached. The current thread must be bound to a VM thread.
*
* @param classContext the class context instance (must not be {@code null})
* @param name the resource name (must not be {@code null})
* @return the list of resource contents as bytes, (not {@code null})
* @throws Thrown if the internal JVM has thrown an exception while loading the resource
*/
List loadResources(ClassContext classContext, String name) throws Thrown;
/**
* Allocate an object without initializing it (all fields/elements will be {@code null}, {@code false}, or zero).
* If the given {@code type} is not initialized, it will be.
*
* @param type the type to allocate (must not be {@code null})
* @return the allocated object (not {@code null})
*/
VmObject allocateObject(ClassObjectType type);
/**
* Invoke a constructor reflectively. Primitive arguments should be boxed.
*
* @param method the constructor to invoke
* @param instance the instance to invoke upon
* @param args the arguments, whose times must match the constructor's expectations
*/
void invokeExact(ConstructorElement method, VmObject instance, List