bool JavaVM::execThread(StackFrame * currentThread, int timeEscalonator) { try { while(time(NULL) + timeEscalonator > time(NULL)) { Frame * f = currentThread->top(); //here I get the top frame, if a new method was stacked, I got him. if (!checkFrame(f)) break; if (f->_method->getAccessFlags() & ACC_NATIVE) { invokeNativeMethod(f); //exceptions need to set _hasException on Frame and exception needs to be on top _operandStack continue; } //return true, false or undefined, true if this method is finished, false if it doesnt finished yet, undefined if it thorws an exception boost::logic::tribool ret = this->executionEngine(currentThread); if (!ret) { /* not finished yet*/ } else if (ret) { if (f->_method->getAccessFlags() & ACC_SYNCHRONIZED) { f->_localVariable[0]._var._objectref->_monitor--; this->notify(f->_localVariable[0]._var._objectref); //if this method has ACC_SYNCHRONIZED I need to do monitorexit //I need to sinalize I have unlock this object } Variable ret; if (currentThread->methodSDone(&ret)) currentThread->top()->_operandStack.push(ret); } else //exception { currentThread->setException(); } } } catch(std::exception & ex) { // throw ex; return false; } return true; }
/** * This method will open a new frame and call the method indicated in the parameters. * * \param mic A pointer to a method definition to be invoked. * \param returnFromVM if TRUE: When a frame is popped (using pop_frame) and this is true, * the execute() - function will return; if FALSE: No return will happen from the execute() * function. Shall be set to TRUE when a native function is calling a java method. */ void invokeCommon(const methodInClass* mic, BOOL returnFromVM) { BEGIN; if (mic->nativeIndex > 0) { CALL(invokeNativeMethod(mic->nativeIndex)) ; } else { //CALL(validateStackables(stack, context.operandStackPointer)); // Allocate space for local variables (arguments are already allocated): // Need to initialize stack space otherwise the marking phase of mark & sweep will see // some the data on the stack as object refs: int i = mic->numberOfLocalVariables - mic->numberOfArguments; while (i-- > 0) { // Push some non-GC critical dummy data: operandStackPushJavaInt(0); } // This is a no-go: context.operandStackPointer += localVariableCount - argumentCount; // since it might leave jref - lookalikes on the stack, which might confuse GC push_frame(mic->numberOfLocalVariables, mic->classId, mic->codeOffset, returnFromVM); //CALL(validateStackables(stack, context.operandStackPointer)); } END; }