| //===--------- Object.cc - Common objects for vmlets ----------------------===// |
| // |
| // The Micro Virtual Machine |
| // |
| // This file is distributed under the University of Illinois Open Source |
| // License. See LICENSE.TXT for details. |
| // |
| //===----------------------------------------------------------------------===// |
| |
| #include <cstdio> |
| #include <cstdlib> |
| |
| #include "MvmGC.h" |
| #include "mvm/Object.h" |
| #include "mvm/PrintBuffer.h" |
| #include "mvm/VirtualMachine.h" |
| |
| using namespace mvm; |
| |
| extern "C" void printFloat(float f) { |
| fprintf(stderr, "%f\n", f); |
| } |
| |
| extern "C" void printDouble(double d) { |
| fprintf(stderr, "%f\n", d); |
| } |
| |
| extern "C" void printLong(sint64 l) { |
| fprintf(stderr, "%lld\n", (long long int)l); |
| } |
| |
| extern "C" void printInt(sint32 i) { |
| fprintf(stderr, "%d\n", i); |
| } |
| |
| extern "C" void printObject(void* ptr) { |
| fprintf(stderr, "%p\n", ptr); |
| } |
| |
| extern "C" void write_ptr(PrintBuffer* buf, void* obj) { |
| buf->writePtr(obj); |
| } |
| |
| extern "C" void write_int(PrintBuffer* buf, int a) { |
| buf->writeS4(a); |
| } |
| |
| extern "C" void write_str(PrintBuffer* buf, char* a) { |
| buf->write(a); |
| } |
| |
| void Object::default_print(const gc *o, PrintBuffer *buf) { |
| llvm_gcroot(o, 0); |
| buf->write("<Object@"); |
| buf->writePtr((void*)o); |
| buf->write(">"); |
| } |
| |
| void VirtualMachine::waitForExit() { |
| threadLock.lock(); |
| |
| while (!doExit) { |
| threadVar.wait(&threadLock); |
| if (exitingThread != NULL) { |
| Thread* th = exitingThread; |
| exitingThread = NULL; |
| mvm::Thread::releaseThread(th); |
| } |
| } |
| |
| threadLock.unlock(); |
| } |
| |
| void VirtualMachine::exit() { |
| doExit = true; |
| threadLock.lock(); |
| threadVar.signal(); |
| threadLock.unlock(); |
| } |