Search in sources :

Example 31 with RVMClass

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("}");
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) Services.unboxedValueString(org.jikesrvm.util.Services.unboxedValueString) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 32 with RVMClass

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);
}
Also used : RVMClass(org.jikesrvm.classloader.RVMClass)

Example 33 with RVMClass

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);
        }
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Entrypoint(org.vmmagic.pragma.Entrypoint) RVMField(org.jikesrvm.classloader.RVMField) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 34 with RVMClass

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);
}
Also used : NormalMethod(org.jikesrvm.classloader.NormalMethod) TypeReference(org.jikesrvm.classloader.TypeReference) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 35 with RVMClass

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.]");
}
Also used : RVMClassLoader(org.jikesrvm.classloader.RVMClassLoader) TypeReference(org.jikesrvm.classloader.TypeReference) Atom(org.jikesrvm.classloader.Atom) Entrypoint(org.vmmagic.pragma.Entrypoint) RVMClass(org.jikesrvm.classloader.RVMClass) Entrypoint(org.vmmagic.pragma.Entrypoint)

Aggregations

RVMClass (org.jikesrvm.classloader.RVMClass)69 RVMMethod (org.jikesrvm.classloader.RVMMethod)28 TypeReference (org.jikesrvm.classloader.TypeReference)22 RVMType (org.jikesrvm.classloader.RVMType)20 Atom (org.jikesrvm.classloader.Atom)14 RVMField (org.jikesrvm.classloader.RVMField)11 RVMArray (org.jikesrvm.classloader.RVMArray)8 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)8 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)7 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)7 Address (org.vmmagic.unboxed.Address)7 NormalMethod (org.jikesrvm.classloader.NormalMethod)6 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)6 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)6 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)5