diff -ur kaffe-1.1.5/kaffe/kaffevm/intrp/machine.c kaffe-1.1.5-jsg-backup/kaffe/kaffevm/intrp/machine.c --- kaffe-1.1.5/kaffe/kaffevm/intrp/machine.c 2005-04-05 12:46:02.000000000 -0500 +++ kaffe-1.1.5-jsg-backup/kaffe/kaffevm/intrp/machine.c 2005-07-27 13:15:59.000000000 -0500 @@ -49,6 +49,13 @@ #include "support.h" #include "thread.h" +// JSG { +char jsg_fname[20]; +char srmain[] = "SimRunnableMain"; +char piminstr[] = "com/cogent/instructions/PIM_instrs"; +char spil[] = "setPIMInstrLatency"; +// } JSG + /* * Define information about this engine. */ @@ -138,6 +145,7 @@ /* If this is native, then call the real function */ methaccflags = meth->accflags; + if (methaccflags & ACC_NATIVE) { NDBG( dprintf("Call to native %s.%s%s.\n", meth->class->name->data, meth->name->data, METHOD_SIGD(meth)); ); if (methaccflags & ACC_STATIC) { @@ -173,6 +181,44 @@ mobj = 0; npc = 0; + // JSG { + // We need to get the thread data into something we can access. + threadData *BC_thread_data = THREAD_DATA(); + // } JSG + + // JSG { + if (!(methaccflags & ACC_NATIVE)) { + // Let's only count non-native method calls + // A function call has been made, adjust accordingly. + + if(strcmp(meth->name->data, srmain) == 0) + { // entering SimRunnableMain + + BC_thread_data->BCstack++; + BC_thread_data->BCflag++; + + //jsg_stack++; + //jsg_flag++; + + // Throw some debugging out for the world. + // printf("Call: %s.%s%s. \n", meth->class->name->data, meth->name->data, METHOD_SIGD(meth)); + } + + if(strcmp(meth->class->name->data, piminstr) == 0) + { // entering PIM_instrs.* + + BC_thread_data->BCstack++; + BC_thread_data->BCflag--; + + //jsg_stack++; + //jsg_flag--; + + // Throw some debugging out for the world. + // printf("Call: %s.%s%s. \n", meth->class->name->data, meth->name->data, METHOD_SIGD(meth)); + } + } + // } JSG + /* If we have any exception handlers we must prepare to catch them. * We also need to catch if we are synchronised (so we can release it). */ @@ -235,6 +281,36 @@ runVirtualMachine(meth, lcl, sp, npc, retval, &mjbuf, thread_data); end: + // JSG { + // A function call has exited, adjust accordingly. + + if(strcmp(meth->name->data, srmain) == 0) + { // leaving SimRunnableMain() + + BC_thread_data->BCstack--; + BC_thread_data->BCflag--; + + //jsg_stack--; + //jsg_flag--; + + // Throw some debugging out for the world. + // printf("Return: %s.%s%s.\n", meth->class->name->data, meth->name->data, METHOD_SIGD(meth)); + } + + if(strcmp(meth->class->name->data, piminstr) == 0) + { // leaving PIM_instrs.* + + BC_thread_data->BCstack--; + BC_thread_data->BCflag++; + + //jsg_stack--; + //jsg_flag++; + + // Throw some debugging out for the world. + // printf("Return: %s.%s%s.\n", meth->class->name->data, meth->name->data, METHOD_SIGD(meth)); + } + // } JSG + /* Unsync. if required */ if (mobj != 0) { locks_internal_unlockMutex(&mobj->lock, NULL); @@ -242,7 +318,8 @@ cleanupExceptionHandling(&mjbuf, thread_data); -RDBG( dprintf("Returning from method %s%s.\n", meth->name->data, METHOD_SIGD(meth)); ); + NDBG( dprintf("Returning from method %s%s.\n", meth->name->data, METHOD_SIGD(meth)); ); + } void runVirtualMachine(methods *meth, slots *lcl, slots *sp, uintp npc, slots *retval, volatile VmExceptHandler *mjbuf, threadData *thread_data) { @@ -265,8 +342,20 @@ Hjava_lang_Class* crinfo; errorInfo einfo; + // JSG { + // We need to get the thread data into something we can access. + threadData *BC_thread_data = THREAD_DATA(); + // } JSG + /* Finally we get to actually execute the machine */ for (;;) { + // JSG { + // Actually increment the bytecode count. + if(BC_thread_data->BCflag == 1) + { + BC_thread_data->BCcount++; + } + // } JSG register uintp pc = npc; assert(npc < meth->c.bcode.codelen); diff -ur kaffe-1.1.5/kaffe/kaffevm/kaffe.def kaffe-1.1.5-jsg-backup/kaffe/kaffevm/kaffe.def --- kaffe-1.1.5/kaffe/kaffevm/kaffe.def 2005-04-05 12:45:58.000000000 -0500 +++ kaffe-1.1.5-jsg-backup/kaffe/kaffevm/kaffe.def 2005-07-27 13:22:06.000000000 -0500 @@ -2111,11 +2111,26 @@ define_insn(IRETURN) { trace_jcode ("ireturn\n"); - check_stack_int(0); - monitor_exit(); - returnarg_int(rstack(0)); + + // JSG { + if(strcmp(meth->name->data, srmain) == 0) + { + // retval[0].v.tint = jsg_count; + retval[0].v.tint = BC_thread_data->BCcount; + BC_thread_data->BCcount = 0; + + } + else if(strcmp(meth->name->data, spil) == 0) + { + BC_thread_data->BCcount += (rstack(0))[0].v.tint; + } + else + { + returnarg_int(rstack(0)); + } + // } JSG ret(); } @@ -2168,6 +2183,7 @@ trace_jcode ("return\n"); monitor_exit(); + #if defined(ENABLE_JVMPI) softcall_exit_method(globalMethod); #endif diff -ur kaffe-1.1.5/kaffe/kaffevm/thread.c kaffe-1.1.5-jsg-backup/kaffe/kaffevm/thread.c --- kaffe-1.1.5/kaffe/kaffevm/thread.c 2005-04-05 12:45:59.000000000 -0500 +++ kaffe-1.1.5-jsg-backup/kaffe/kaffevm/thread.c 2005-07-27 12:18:31.000000000 -0500 @@ -84,6 +84,12 @@ thread_data->jniEnv = &Kaffe_JNINativeInterface; thread_data->needOnStack = STACK_HIGH; + + // JSG { + thread_data->BCcount = 0; + thread_data->BCstack = 0; + thread_data->BCflag = 0; + // } JSG } /* diff -ur kaffe-1.1.5/kaffe/kaffevm/threadData.h kaffe-1.1.5-jsg-backup/kaffe/kaffevm/threadData.h --- kaffe-1.1.5/kaffe/kaffevm/threadData.h 2005-04-05 12:45:59.000000000 -0500 +++ kaffe-1.1.5-jsg-backup/kaffe/kaffevm/threadData.h 2005-07-27 12:14:05.000000000 -0500 @@ -34,6 +34,12 @@ VmExceptHandler *exceptPtr; struct Hjava_lang_Throwable *exceptObj; int needOnStack; + + /* things required for JSGTHREADS */ + int BCcount; + int BCstack; + int BCflag; + } threadData; #define THREAD_DATA_INITIALIZED(td) ((td)->jniEnv != NULL)