[vmkit-commits] [vmkit] r86472 - in /vmkit/trunk: include/mvm/Threads/Thread.h lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/Runtime/Object.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Nov 8 07:47:45 PST 2009
Author: geoffray
Date: Sun Nov 8 09:47:45 2009
New Revision: 86472
URL: http://llvm.org/viewvc/llvm-project?rev=86472&view=rev
Log:
Use a stack walker class instead of duplicating code, when
walking the stack.
Modified:
vmkit/trunk/include/mvm/Threads/Thread.h
vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
vmkit/trunk/lib/Mvm/Runtime/Object.cpp
Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=86472&r1=86471&r2=86472&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Sun Nov 8 09:47:45 2009
@@ -18,6 +18,7 @@
namespace mvm {
+class MethodInfo;
class VirtualMachine;
/// CircularBase - This class represents a circular list. Classes that extend
@@ -117,7 +118,6 @@
void* currentFP;
};
-
/// Thread - This class is the base of custom virtual machines' Thread classes.
/// It provides static functions to manage threads. An instance of this class
/// contains all thread-specific informations.
@@ -362,6 +362,30 @@
};
+/// StackWalker - This class walks the stack of threads, returning a MethodInfo
+/// object at each iteration.
+///
+class StackWalker {
+public:
+ void** addr;
+ void* ip;
+ KnownFrame* frame;
+ mvm::Thread* thread;
+
+ StackWalker(mvm::Thread* th) {
+ thread = th;
+ addr = mvm::Thread::get() == th ? (void**)FRAME_PTR() :
+ (void**)th->waitOnSP();
+ frame = th->lastKnownFrame;
+ assert(addr && "No address to start with");
+ }
+
+ void operator++();
+
+ MethodInfo* get();
+
+};
+
} // end namespace mvm
#endif // MVM_THREAD_H
Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=86472&r1=86471&r2=86472&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Sun Nov 8 09:47:45 2009
@@ -62,26 +62,37 @@
}
void Thread::printBacktrace() {
- VirtualMachine* vm = MyVM;
- void** addr = mvm::Thread::get() == this ? (void**)FRAME_PTR() :
- (void**)waitOnSP();
- mvm::KnownFrame* currentKnownFrame = lastKnownFrame;
- while (addr < baseSP && addr < addr[0]) {
- void* ip = FRAME_IP(addr);
- mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
- MI->print(ip, addr);
-
- if (currentKnownFrame && addr == currentKnownFrame->currentFP) {
- currentKnownFrame = currentKnownFrame->previousFrame;
- if (currentKnownFrame) {
- addr = (void**)currentKnownFrame->currentFP;
- currentKnownFrame = currentKnownFrame->previousFrame;
+ StackWalker Walker(this);
+
+ while (MethodInfo* MI = Walker.get()) {
+ MI->print(Walker.ip, Walker.addr);
+ ++Walker;
+ }
+}
+
+MethodInfo* StackWalker::get() {
+ if (addr == thread->baseSP) return 0;
+ ip = FRAME_IP(addr);
+ bool isStub = ((unsigned char*)ip)[0] == 0xCE;
+ if (isStub) ip = addr[2];
+ return thread->MyVM->IPToMethodInfo(ip);
+}
+
+void StackWalker::operator++() {
+ if (addr < thread->baseSP && addr < addr[0]) {
+ if (frame && addr == frame->currentFP) {
+ frame = frame->previousFrame;
+ if (frame) {
+ addr = (void**)frame->currentFP;
+ frame = frame->previousFrame;
} else {
addr = (void**)addr[0];
}
} else {
addr = (void**)addr[0];
}
+ } else {
+ addr = (void**)thread->baseSP;
}
}
Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=86472&r1=86471&r2=86472&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sun Nov 8 09:47:45 2009
@@ -262,32 +262,12 @@
}
void PreciseStackScanner::scanStack(mvm::Thread* th) {
- VirtualMachine* vm = th->MyVM;
-
- void** addr = mvm::Thread::get() == th ?
- (void**)FRAME_PTR() : (void**)th->waitOnSP();
- assert(addr && "No address to start with");
+ StackWalker Walker(th);
- mvm::KnownFrame* currentKnownFrame = th->lastKnownFrame;
- while (addr < th->baseSP && addr < addr[0]) {
- void* ip = FRAME_IP(addr);
- bool isStub = ((unsigned char*)ip)[0] == 0xCE;
- if (isStub) ip = addr[2];
- mvm::MethodInfo* MI = vm->IPToMethodInfo(ip);
- MI->scan(0, ip, addr);
-
- if (currentKnownFrame && addr == currentKnownFrame->currentFP) {
- currentKnownFrame = currentKnownFrame->previousFrame;
- if (currentKnownFrame) {
- addr = (void**)currentKnownFrame->currentFP;
- currentKnownFrame = currentKnownFrame->previousFrame;
- } else {
- addr = (void**)addr[0];
- }
- } else {
- addr = (void**)addr[0];
- }
- }
+ while (MethodInfo* MI = Walker.get()) {
+ MI->scan(0, Walker.ip, Walker.addr);
+ ++Walker;
+ }
}
More information about the vmkit-commits
mailing list