Esempio n. 1
0
int executeMethod(MethodInfo *startup, StackFrame *stack, SimpleConstantPool *p)
{
    int i = 0;
    int j = 0;
    char name[255];
    CodeAttribute ca;
    memset(&ca, 0 , sizeof(CodeAttribute));
    for (j = 0 ; j < startup->attributes_count ; j++) {
        convertToCodeAttribute(&ca, &startup->attributes[j]);
        getUTF8String(p, ca.attribute_name_index, 255, name);
        if (memcmp(name, "Code", 4) != 0) continue;
#if SIMPLE_JVM_DEBUG
        printf("----------------------------------------\n");
        printf("code dump\n");
        printCodeAttribute(&ca, p);
        printf("----------------------------------------\n");
#endif
        unsigned char *pc = ca.code;
        if (run == 0)
            exit(1);
        do {
#if 1
            opCodeFunc func = findOpCodeFunc(pc[0]);
            if (func != 0) {
                i = func(&pc , &stackFrame, p);
            }
            if (i < 0) break;
#endif
        } while (1);
    }
    return 0;
}
void printCodeAttribute( CodeAttribute *ca, SimpleConstantPool *p ) {
    int i = 0;
    int tmp = 0;
    char name[255];
    unsigned char opCode = 0;
    getUTF8String(p,ca->attribute_name_index,255,name);
    printf("attribute name : %s\n", name );
    printf("attribute length: %d\n", ca->attribute_length );

    printf("max_stack: %d\n", ca->max_stack );
    printf("max_locals: %d\n", ca->max_locals );
    printf("code_length: %d\n", ca->code_length );
    unsigned char *pc = ca->code;
    i = 0;
    do {
        char *opName = findOpCode( pc[0] );
        if ( opName == 0 ) {
            printf("Unknow OpCode %02X\n", pc[0] );
            exit(1);
        }
        printf("%s \n", opName);
#if 0
        opCodeFunc func= findOpCodeFunc(pc);
        if ( func != 0 ) 
            func(opCode, &stackFrame );
#endif
        tmp = findOpCodeOffset(pc[0]);
        pc += tmp;
        i += tmp;
    } while ( i < ca->code_length ) ;
}