use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class GenerateInterfaceDeclarations method emitBootRecordInitialization.
// Emit declarations for BootRecord object.
//
static void emitBootRecordInitialization() {
RVMClass bootRecord = TypeReference.findOrCreate(org.jikesrvm.runtime.BootRecord.class).resolve().asClass();
RVMField[] fields = bootRecord.getDeclaredFields();
// emit field initializers
//
pln("static void setLinkage(struct BootRecord* br){");
for (int i = fields.length; --i >= 0; ) {
RVMField field = fields[i];
if (field.isStatic()) {
continue;
}
String fieldName = field.getName().toString();
if (fieldName.indexOf("gcspy") > -1 && !VM.BuildWithGCSpy) {
// ugh. NOTE: ugly hack to side-step unconditional inclusion of GCSpy stuff
continue;
}
int suffixIndex = fieldName.indexOf("IP");
if (suffixIndex > 0) {
// java field "xxxIP" corresponds to C function "xxx"
String functionName = fieldName.substring(0, suffixIndex);
// e. g.,
// sysFOOIP = (int) sysFOO;
pln(" br->" + fieldName + " = (Address)" + functionName + ";");
} else if (fieldName.equals("sysJavaVM")) {
pln(" br->" + fieldName + " = (Address)&" + fieldName + ";");
}
}
pln("}");
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class GenerateInterfaceDeclarations method emitBootRecordDeclarations.
static void emitBootRecordDeclarations() {
RVMClass bootRecord = TypeReference.findOrCreate(org.jikesrvm.runtime.BootRecord.class).resolve().asClass();
emitCDeclarationsForJavaType("BootRecord", bootRecord);
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class EntrypointHelper method verifyPresenceOfEntrypointAnnotation.
private static void verifyPresenceOfEntrypointAnnotation(RVMMember member) {
if (VM.VerifyAssertions && !(member.isAnnotationPresent(Entrypoint.class))) {
// For certain methods, it's clear that they're accessed by the
// compiler, so an annotation is not required:
boolean annotationRequired = true;
if (member instanceof RVMMethod) {
RVMMethod m = (RVMMethod) member;
RVMClass declClass = m.getDeclaringClass();
if (declClass.getTypeRef().isMagicType() || declClass.getTypeRef().isUnboxedType() || // it's the VM's job to handle those correctly
declClass.getPackageName().startsWith("java.lang")) {
annotationRequired = false;
}
}
// Don't require annotations on fields for the class library.
if (member instanceof RVMField) {
RVMField field = (RVMField) member;
RVMClass declClass = field.getDeclaringClass();
if (declClass.getPackageName().startsWith("java.lang")) {
annotationRequired = false;
}
}
if (annotationRequired) {
String msg = "WARNING: MISSING @Entrypoint ANNOTATION: " + member + " is missing an @Entrypoint annotation!";
throw new Error(msg);
}
}
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class EntrypointHelper method getMethod.
/**
* Get description of virtual machine method.
* @param klass class containing method
* @param member member name - something like "invokestatic"
* @param descriptor member descriptor - something like "()V"
* @return corresponding RVMMethod
*/
public static NormalMethod getMethod(Class<?> klass, String member, String descriptor) {
if (!VM.runningVM) {
// avoid compiling this code into the boot image
try {
TypeReference klassTRef = TypeReference.findOrCreate(klass);
RVMClass cls = klassTRef.resolve().asClass();
cls.resolve();
Atom memName = Atom.findOrCreateAsciiAtom(member);
Atom memDescriptor = Atom.findOrCreateAsciiAtom(descriptor);
NormalMethod m = (NormalMethod) cls.findDeclaredMethod(memName, memDescriptor);
if (m != null) {
verifyPresenceOfEntrypointAnnotation(m);
m.setRuntimeServiceMethod(true);
return m;
}
} catch (Throwable t) {
throw new Error("Entrypoints.getField: can't resolve class=" + klass + " member=" + member + " desc=" + descriptor, t);
}
}
throw new Error("Entrypoints.getMethod: can't resolve class=" + klass + " method=" + member + " desc=" + descriptor);
}
use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.
the class MainThread method run.
/**
* Run "main" thread.
* <p>
* This code could be made a little shorter by relying on Reflection
* to do the classloading and compilation. We intentionally do it here
* to give us a chance to provide error messages that are specific to
* not being able to find the main class the user wants to run.
* This may be a little silly, since it results in code duplication
* just to provide debug messages in a place where very little is actually
* likely to go wrong, but there you have it....
*/
@Override
@Entrypoint
public void run() {
launched = true;
if (dbg)
VM.sysWriteln("MainThread.run() starting ");
// Set up application class loader
ClassLoader cl = RVMClassLoader.getApplicationClassLoader();
setContextClassLoader(cl);
runAgents(cl);
if (dbg)
VM.sysWrite("[MainThread.run() loading class to run... ");
// find method to run
// load class specified by args[0]
RVMClass cls = null;
try {
Atom mainAtom = Atom.findOrCreateUnicodeAtom(args[0]);
TypeReference mainClass = TypeReference.findOrCreate(cl, mainAtom.descriptorFromClassName());
cls = mainClass.resolve().asClass();
cls.prepareForFirstUse();
} catch (NoClassDefFoundError e) {
if (dbg)
VM.sysWrite("failed.]");
// no such class
VM.sysWriteln(e.toString());
return;
}
if (dbg)
VM.sysWriteln("loaded.]");
// find "main" method
//
mainMethod = cls.findMainMethod();
if (mainMethod == null) {
// no such method
VM.sysWriteln(cls + " doesn't have a \"public static void main(String[])\" method to execute");
return;
}
if (dbg)
VM.sysWrite("[MainThread.run() making arg list... ");
// create "main" argument list
//
String[] mainArgs = new String[args.length - 1];
for (int i = 0, n = mainArgs.length; i < n; ++i) {
mainArgs[i] = args[i + 1];
}
if (dbg)
VM.sysWriteln("made.]");
if (dbg)
VM.sysWrite("[MainThread.run() compiling main(String[])... ");
mainMethod.compile();
if (dbg)
VM.sysWriteln("compiled.]");
// Notify other clients that the startup is complete.
//
Callbacks.notifyStartup();
if (dbg)
VM.sysWriteln("[MainThread.run() invoking \"main\" method... ");
// invoke "main" method with argument list
Reflection.invoke(mainMethod, null, null, new Object[] { mainArgs }, true);
if (dbg)
VM.sysWriteln(" MainThread.run(): \"main\" method completed.]");
}
Aggregations