uintptr_t WINAPI MemoryManager::CheckPdaRoots(void* arg) { #ifndef _GC_SERIAL EnterCriticalSection(&pda_frame_cs); #endif #ifdef _DEBUG wcout << L"----- PDA frames(s): num=" << pda_frames.size() << L"; thread=" << GetCurrentThread()<< L" -----" << endl; wcout << L"memory types:" << endl; #endif set<StackFrame**, StackFrame**>::iterator iter; for(iter = pda_frames.begin(); iter != pda_frames.end(); ++iter) { StackFrame** frame = *iter; StackMethod* mthd = (*frame)->method; long* mem = (*frame)->mem; #ifdef _DEBUG wcout << L"\t===== PDA method: name=" << mthd->GetName() << L", addr=" << mthd << L", num=" << mthd->GetNumberDeclarations() << L" =====" << endl; #endif // mark self CheckObject((long*)(*mem), true, 1); if(mthd->HasAndOr()) { mem += 2; } else { mem++; } // mark rest of memory CheckMemory(mem, mthd->GetDeclarations(), mthd->GetNumberDeclarations(), 0); } #ifndef _GC_SERIAL LeaveCriticalSection(&pda_frame_cs); #endif #ifndef GC_SERIAL EnterCriticalSection(&pda_monitor_cs); #endif #ifdef _DEBUG wcout << L"----- PDA method root(s): num=" << pda_monitors.size() << L"; thread=" << GetCurrentThread()<< L" -----" << endl; wcout << L"memory types:" << endl; #endif // look at pda methods unordered_map<StackFrameMonitor*, StackFrameMonitor*>::iterator pda_iter; for(pda_iter = pda_monitors.begin(); pda_iter != pda_monitors.end(); ++pda_iter) { // gather stack frames StackFrameMonitor* monitor = pda_iter->first; long call_stack_pos = *(monitor->call_stack_pos); if (call_stack_pos > 0) { StackFrame** call_stack = monitor->call_stack; StackFrame* cur_frame = *(monitor->cur_frame); // copy frames locally vector<StackFrame*> frames; frames.push_back(cur_frame); while (--call_stack_pos > -1) { frames.push_back(call_stack[call_stack_pos]); } for (size_t i = 0; i < frames.size(); ++i) { StackMethod* mthd = frames[i]->method; long* mem = frames[i]->mem; #ifdef _DEBUG wcout << L"\t===== PDA method: name=" << mthd->GetName() << L", addr=" << mthd << L", num=" << mthd->GetNumberDeclarations() << L" =====" << endl; #endif // mark self CheckObject((long*)(*mem), true, 1); if (mthd->HasAndOr()) { mem += 2; } else { mem++; } // mark rest of memory CheckMemory(mem, mthd->GetDeclarations(), mthd->GetNumberDeclarations(), 0); } } } #ifndef GC_SERIAL LeaveCriticalSection(&pda_monitor_cs); #endif return 0; }
void Runtime::Debugger::ProcessInfo(Info* info) { const wstring &cls_name = info->GetClassName(); const wstring &mthd_name = info->GetMethodName(); #ifdef _DEBUG wcout << L"--- info class=" << cls_name << L", method=" << mthd_name << L" ---" << endl; #endif if(interpreter) { // method info if(cls_name.size() > 0 && mthd_name.size() > 0) { StackClass* klass = cur_program->GetClass(cls_name); if(klass && klass->IsDebug()) { vector<StackMethod*> methods = klass->GetMethods(mthd_name); if(methods.size() > 0) { for(size_t i = 0; i < methods.size(); i++) { StackMethod* method = methods[i]; wcout << L" class: type=" << klass->GetName() << L", method=" << PrintMethod(method) << endl; if(method->GetNumberDeclarations() > 0) { wcout << L" parameters:" << endl; PrintDeclarations(method->GetDeclarations(), method->GetNumberDeclarations()); } } } else { wcout << L"unable to find method." << endl; is_error = true; } } else { wcout << L"unable to find class." << endl; is_error = true; } } // class info else if(cls_name.size() > 0) { StackClass* klass = cur_program->GetClass(cls_name); if(klass && klass->IsDebug()) { wcout << L" class: type=" << klass->GetName() << endl; // print wcout << L" parameters:" << endl; if(klass->GetNumberInstanceDeclarations() > 0) { PrintDeclarations(klass->GetInstanceDeclarations(), klass->GetNumberInstanceDeclarations()); } } else { wcout << L"unable to find class." << endl; is_error = true; } } // general info else { wcout << L"general info:" << endl; wcout << L" program executable: file='" << program_file << L"'" << endl; // parse method and class names const wstring &long_name = cur_frame->method->GetName(); int end_index = long_name.find_last_of(':'); const wstring &cls_mthd_name = long_name.substr(0, end_index); int mid_index = cls_mthd_name.find_last_of(':'); const wstring &cls_name = cls_mthd_name.substr(0, mid_index); const wstring &mthd_name = cls_mthd_name.substr(mid_index + 1); // print wcout << L" current file='" << cur_file_name << L":" << cur_line_num << L"', method='" << cls_name << L"->" << mthd_name << L"(..)'" << endl; } } else { wcout << L"program is not running." << endl; } }
uintptr_t WINAPI MemoryManager::CheckJitRoots(void* arg) { #ifndef GC_SERIAL EnterCriticalSection(&jit_cs); #endif #ifdef _DEBUG wcout << L"---- Marking JIT method root(s): num=" << jit_roots.size() << L"; thread=" << GetCurrentThread() << L" ------" << endl; wcout << L"memory types: " << endl; #endif unordered_map<long*, ClassMethodId*>::iterator jit_iter; for(jit_iter = jit_roots.begin(); jit_iter != jit_roots.end(); ++jit_iter) { ClassMethodId* id = jit_iter->second; long* mem = id->mem; StackMethod* mthd = prgm->GetClass(id->cls_id)->GetMethod(id->mthd_id); const long dclrs_num = mthd->GetNumberDeclarations(); #ifdef _DEBUG wcout << L"\t===== JIT method: name=" << mthd->GetName() << L", id=" << id->cls_id << L"," << id->mthd_id << L"; addr=" << mthd << L"; num=" << mthd->GetNumberDeclarations() << L" =====" << endl; #endif // check self CheckObject(id->self, true, 1); StackDclr** dclrs = mthd->GetDeclarations(); for(int j = dclrs_num - 1; j > -1; j--) { // update address based upon type switch(dclrs[j]->type) { case FUNC_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": FUNC_PARM: value=" << (*mem) << L"," << *(mem + 1) << endl; #endif // update mem += 2; break; case CHAR_PARM: case INT_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": CHAR_PARM/INT_PARM: value=" << (*mem) << endl; #endif // update mem++; break; case FLOAT_PARM: { #ifdef _DEBUG FLOAT_VALUE value; memcpy(&value, mem, sizeof(FLOAT_VALUE)); wcout << L"\t" << j << L": FLOAT_PARM: value=" << value << endl; #endif // update mem += 2; } break; case BYTE_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": BYTE_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case CHAR_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": CHAR_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case INT_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": INT_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case FLOAT_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": FLOAT_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << L" byte(s)" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << endl; #endif // mark data MarkMemory((long*)(*mem)); // update mem++; break; case OBJ_PARM: { #ifdef _DEBUG wcout << L"\t" << j << L": OBJ_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), id="; if(*mem) { StackClass* tmp = (StackClass*)((long*)(*mem))[SIZE_OR_CLS]; wcout << L"'" << tmp->GetName() << L"'" << endl; } else { wcout << L"Unknown" << endl; } #endif // check object CheckObject((long*)(*mem), true, 1); // update mem++; } break; // TODO: test the code below case OBJ_ARY_PARM: #ifdef _DEBUG wcout << L"\t" << j << L": OBJ_ARY_PARM: addr=" << (long*)(*mem) << L"(" << (long)(*mem) << L"), size=" << ((*mem) ? ((long*)(*mem))[SIZE_OR_CLS] : 0) << L" byte(s)" << endl; #endif // mark data if(MarkValidMemory((long*)(*mem))) { long* array = (long*)(*mem); const long size = array[0]; const long dim = array[1]; long* objects = (long*)(array + 2 + dim); for(long k = 0; k < size; k++) { CheckObject((long*)objects[k], true, 2); } } // update mem++; break; default: break; } } // NOTE: this marks temporary variables that are stored in JIT memory // during some method calls. there are 3 integer temp addresses for(int i = 0; i < 8; i++) { CheckObject((long*)mem[i], false, 1); } } #ifndef GC_SERIAL LeaveCriticalSection(&jit_cs); #endif return 0; }