[vmkit-commits] [vmkit] r71978 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMRuntime.cpp Compiler/JITInfo.cpp Compiler/JavaAOTCompiler.cpp Compiler/JavaJIT.cpp Compiler/JavaJITOpcodes.cpp VMCore/JavaArray.cpp VMCore/JavaArray.h VMCore/JavaCache.h VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JavaConstantPool.cpp VMCore/JavaRuntimeJIT.cpp VMCore/JavaString.cpp VMCore/JavaThread.cpp VMCore/JavaTypes.h VMCore/Jni.cpp VMCore/Jnjvm.cpp VMCore/Jnjvm.h VMCore/JnjvmClassLoader.cpp VMCore/LockedMap.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun May 17 07:05:47 PDT 2009


Author: geoffray
Date: Sun May 17 09:05:45 2009
New Revision: 71978

URL: http://llvm.org/viewvc/llvm-project?rev=71978&view=rev
Log:
Replace PrintBuffer with UTF8Buffer, which does not allocate with the GC.


Modified:
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h
    vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp Sun May 17 09:05:45 2009
@@ -116,7 +116,9 @@
   
   res = loader->loadLib(buf);
  
-   if (res) callOnLoad(res, loader, vm);
+  if (res) callOnLoad(res, loader, vm);
+
+  delete[] buf;
 
   return res != 0;
 }

Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Sun May 17 09:05:45 2009
@@ -375,7 +375,7 @@
     (JavaLLVMCompiler*)signature->initialLoader->getCompiler();
   std::string name;
   if (Mod->isStaticCompiling()) {
-    name += signature->printString();
+    name += UTF8Buffer(signature->keyName).cString();
     name += virt ? "virtual_ap" : "static_ap";
   } else {
     name = "";

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sun May 17 09:05:45 2009
@@ -66,7 +66,8 @@
     
       GlobalVariable* varGV = 
         new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0,
-                           classDef->printString(), getLLVMModule());
+                           UTF8Buffer(classDef->name).cString(),
+                           getLLVMModule());
     
       nativeClasses.insert(std::make_pair(classDef, varGV));
 
@@ -96,7 +97,8 @@
       GlobalVariable* varGV = 
         new GlobalVariable(Ty, false, GlobalValue::InternalLinkage,
                            Constant::getNullValue(Ty),
-                           classDef->printString(), getLLVMModule());
+                           UTF8Buffer(classDef->name).cString(),
+                           getLLVMModule());
     
       arrayClasses.insert(std::make_pair(classDef->asArrayClass(), varGV));
       return varGV;
@@ -277,7 +279,7 @@
     LLVMClassInfo* LCI = getClassInfo(classDef);
     const Type* Ty = LCI->getStaticType();
     Ty = Ty->getContainedType(0);
-    std::string name(classDef->printString());
+    std::string name(UTF8Buffer(classDef->name).cString());
     name += "_static";
     GlobalVariable* varGV = 
       new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage,
@@ -317,7 +319,7 @@
       dyn_cast<ArrayType>(JnjvmModule::VTType->getContainedType(0));
     const PointerType* PTy = dyn_cast<PointerType>(ATy->getContainedType(0));
     ATy = ArrayType::get(PTy, size);
-    std::string name(classDef->printString());
+    std::string name(UTF8Buffer(classDef->name).cString());
     name += "_VT";
     // Do not set a virtual table as a constant, because the runtime may
     // modify it.
@@ -1523,7 +1525,7 @@
                                       Signdef* sign, bool stat) {
  
   fprintf(stderr, "Warning: emitting a callback from %s (%d)\n",
-          cl->printString(), index);
+          UTF8Buffer(cl->name).cString(), index);
   Function* func = 0;
   LLVMSignatureInfo* LSI = getSignatureInfo(sign);
   

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Sun May 17 09:05:45 2009
@@ -226,8 +226,9 @@
 
 llvm::Function* JavaJIT::nativeCompile(intptr_t natPtr) {
   
-  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "native compile %s\n",
-              compilingMethod->printString());
+  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "native compile %s.%s\n",
+              UTF8Buffer(compilingClass->name).cString(),
+              UTF8Buffer(compilingMethod->name).cString());
   
   bool stat = isStatic(compilingMethod->access);
 
@@ -258,8 +259,9 @@
     else
       ReturnInst::Create(currentBlock);
   
-    PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "end native compile %s\n",
-                compilingMethod->printString());
+    PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "end native compile %s.%s\n",
+                UTF8Buffer(compilingClass->name).cString(),
+                UTF8Buffer(compilingMethod->name).cString());
   
     llvmFunction->setLinkage(GlobalValue::ExternalLinkage);
     return llvmFunction;
@@ -390,8 +392,9 @@
   else
     ReturnInst::Create(currentBlock);
   
-  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "end native compile %s\n",
-              compilingMethod->printString());
+  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "end native compile %s.%s\n",
+              UTF8Buffer(compilingClass->name).cString(),
+              UTF8Buffer(compilingMethod->name).cString());
   
   func->setLinkage(GlobalValue::ExternalLinkage);
   
@@ -590,15 +593,17 @@
 Instruction* JavaJIT::inlineCompile(BasicBlock*& curBB,
                                     BasicBlock* endExBlock,
                                     std::vector<Value*>& args) {
-  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "inline compile %s\n",
-              compilingMethod->printString());
+  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "inline compile %s.%s\n",
+              UTF8Buffer(compilingClass->name).cString(),
+              UTF8Buffer(compilingMethod->name).cString());
   
   Attribut* codeAtt = compilingMethod->lookupAttribut(Attribut::codeAttribut);
   
   if (!codeAtt) {
     fprintf(stderr, "I haven't verified your class file and it's malformed:"
-                    " no code attribut found for %s!\n",
-                    compilingMethod->printString());
+                    " no code attribut found for %s.%s!\n",
+                    UTF8Buffer(compilingClass->name).cString(),
+                    UTF8Buffer(compilingMethod->name).cString());
     abort();
   }
 
@@ -708,8 +713,10 @@
 
   compileOpcodes(&compilingClass->bytes->elements[start], codeLen);
   
-  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "--> end inline compiling %s\n",
-              compilingMethod->printString());
+  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL,
+              "--> end inline compiling %s.%s\n",
+              UTF8Buffer(compilingClass->name).cString(),
+              UTF8Buffer(compilingMethod->name).cString());
 
   curBB = endBlock;
   return endNode;
@@ -718,16 +725,18 @@
 
 
 llvm::Function* JavaJIT::javaCompile() {
-  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "compiling %s\n",
-              compilingMethod->printString());
+  PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "compiling %s.%s\n",
+              UTF8Buffer(compilingClass->name).cString(),
+              UTF8Buffer(compilingMethod->name).cString());
 
   
   Attribut* codeAtt = compilingMethod->lookupAttribut(Attribut::codeAttribut);
   
   if (!codeAtt) {
     fprintf(stderr, "I haven't verified your class file and it's malformed:"
-                    " no code attribut found for %s!\n",
-                    compilingMethod->printString());
+                    " no code attribut found for %s.%s!\n",
+                    UTF8Buffer(compilingClass->name).cString(),
+                    UTF8Buffer(compilingMethod->name).cString());
     abort();
   }
 
@@ -1078,8 +1087,9 @@
     push(res, false);
   } else {
     fprintf(stderr, "I haven't verified your class file and it's malformed:"
-                    " unknown ldc %d in %s!\n", type,
-                    compilingClass->printString());
+                    " unknown ldc %d in %s.%s!\n", type,
+                    UTF8Buffer(compilingClass->name).cString(),
+                    UTF8Buffer(compilingMethod->name).cString());
     abort();
   }
 }

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Sun May 17 09:05:45 2009
@@ -61,8 +61,9 @@
     return I_DOUBLE;
   } else {
     fprintf(stderr, "I haven't verified your class file and it's malformed:"
-                    " unknown array type %d in %s!\n", t,
-                    meth->printString());
+                    " unknown array type %d in %s.%s!\n", t,
+                    UTF8Buffer(meth->classDef->name).cString(),
+                    UTF8Buffer(meth->name).cString());
     abort();
   }
 }
@@ -2194,8 +2195,9 @@
       
       default : {
         fprintf(stderr, "I haven't verified your class file and it's malformed:"
-                    " unknown bytecode %d in %s\n!", bytecodes[i],
-                    compilingClass->printString());
+                    " unknown bytecode %d in %s.%s\n!", bytecodes[i],
+                    UTF8Buffer(compilingClass->name).cString(),
+                    UTF8Buffer(compilingMethod->name).cString());
         abort();
       }
     } 
@@ -2543,8 +2545,9 @@
 
       default : {
         fprintf(stderr, "I haven't verified your class file and it's malformed:"
-                    " unknown bytecode %d in %s!\n", bytecodes[i],
-                    compilingClass->printString());
+                    " unknown bytecode %d in %s.%s!\n", bytecodes[i],
+                    UTF8Buffer(compilingClass->name).cString(),
+                    UTF8Buffer(compilingMethod->name).cString());
         abort();
       }
     }

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp Sun May 17 09:05:45 2009
@@ -45,22 +45,3 @@
 
   return map->lookupOrCreateReader(buf, len);
 }
-
-char* UTF8::printString() const {
-#ifndef DEBUG
-  mvm::NativeString* buf = mvm::NativeString::alloc(size + 1);
-  for (sint32 i = 0; i < size; ++i) {
-    buf->setAt(i, elements[i]);
-  }
-  buf->setAt(size, 0);
-  return buf->cString();
-#else
-  // To bypass GC-allocation, use malloc here. Only when debugging.
-  char* buf = (char*)malloc(size + 1);
-  for (sint32 i = 0; i < size; ++i) {
-    buf[i] =  elements[i];
-  }
-  buf[size] = 0;
-  return buf;
-#endif
-}

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Sun May 17 09:05:45 2009
@@ -15,7 +15,6 @@
 #define JNJVM_JAVA_ARRAY_H
 
 #include "mvm/Allocator.h"
-#include "mvm/PrintBuffer.h"
 
 #include "types.h"
 
@@ -105,7 +104,7 @@
 /// of type uint16) with helper functions for manipulating UTF8. Each JVM
 /// instance hashes UTF8. UTF8 are not allocated by the application's garbage
 /// collector, but resides in permanent memory (e.g malloc).
-class UTF8 : public ArrayUInt16 {
+class UTF8 {
   friend class UTF8Map;
 private:
   
@@ -113,8 +112,7 @@
   /// its objects in permanent memory, not with the garbage collector.
   void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator,
                      sint32 size) {
-    return allocator.Allocate(sizeof(JavaObject) + sizeof(ssize_t) + 
-                              size * sizeof(uint16));
+    return allocator.Allocate(sizeof(ssize_t) + size * sizeof(uint16));
   }
   
   UTF8(sint32 n) {
@@ -122,15 +120,17 @@
   }
 
 public:
-  
+  /// size - The (constant) size of the array.
+  ssize_t size;
+
+  /// elements - Elements of this array. The size here is different than the
+  /// actual size of the Java array. This is to facilitate Java array accesses
+  /// in JnJVM code. The size should be set to zero, but this is invalid C99.
+  uint16 elements[1];
   
   /// extract - Similar, but creates it in the map.
   const UTF8* extract(UTF8Map* map, uint32 start, uint32 len) const;
-
-  
-  /// printString - Allocates a C string with the contents of this UTF8.
-  char* printString() const;
-
+ 
   /// equals - Are the two UTF8s equal?
   bool equals(const UTF8* other) const {
     if (other == this) return true;
@@ -154,6 +154,41 @@
   
 };
 
+
+/// UTF8Buffer - Helper class to create char* buffers suitable for
+/// printf.
+///
+class UTF8Buffer {
+
+  /// buffer - The buffer that holds a string representation.
+  ///
+  char* buffer;
+public:
+
+  /// UTF8Buffer - Create a buffer with the following UTF8.
+  ///
+  UTF8Buffer(const UTF8* val) {
+    buffer = new char[val->size];
+    for (sint32 i = 0; i < val->size; ++i)
+      buffer[i] = val->elements[i];
+  }
+
+  /// ~UTF8Buffer - Delete the buffer, as well as all dynamically
+  /// allocated memory.
+  ///
+  ~UTF8Buffer() {
+    delete[] buffer;
+  }
+
+  /// cString - Return a C string representation of the buffer, suitable
+  /// for printf.
+  ///
+  const char* cString() {
+    return buffer;
+  }
+
+};
+
 } // end namespace jnjvm
 
 #endif

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h Sun May 17 09:05:45 2009
@@ -23,7 +23,6 @@
 
 #include "mvm/Allocator.h"
 #include "mvm/Object.h"
-#include "mvm/PrintBuffer.h"
 #include "mvm/Threads/Locks.h"
 
 #include "types.h"

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sun May 17 09:05:45 2009
@@ -592,7 +592,7 @@
     } else {
       fprintf(stderr, "I haven't verified your class file and it's malformed:"
                       " unknown constant %s!\n",
-                      type->printString());
+                      UTF8Buffer(type->keyName).cString());
       abort();
     }
   } 

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sun May 17 09:05:45 2009
@@ -15,7 +15,6 @@
 
 #include "mvm/Allocator.h"
 #include "mvm/Object.h"
-#include "mvm/PrintBuffer.h"
 #include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
 
@@ -420,12 +419,6 @@
   ///
   void TRACER;
   
-  /// printString - Prints the class.
-  ///
-  const char *printString() const {
-    return name->printString();
-  }
-
   /// inheritName - Does this class in its class hierarchy inherits
   /// the given name? Equality is on the name. This function does not take
   /// into account array classes.
@@ -1155,12 +1148,6 @@
     return _signature;
   }
   
-  /// printString - Output a string representation of the method.
-  ///
-  const char* printString() const {
-    return name->printString();
-  }
- 
   /// toString - Return an array of chars, suitable for creating a string.
   ///
   ArrayUInt16* toString() const;
@@ -1411,12 +1398,6 @@
   ///
   Attribut* lookupAttribut(const UTF8* key);
 
-  /// printString - Output a string representation of the field.
-  ///
-  const char* printString() const {
-    return name->printString();
-  }
-
   /// getVritual*Field - Get a virtual field of an object.
   ///
   #define GETFIELD(TYPE, TYPE_NAME) \

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Sun May 17 09:05:45 2009
@@ -181,7 +181,8 @@
 
 const UTF8* JavaConstantPool::UTF8At(uint32 entry) {
   if (!((entry > 0) && (entry < ctpSize) && typeAt(entry) == ConstantUTF8)) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   
@@ -218,8 +219,8 @@
     const UTF8* utf8 = loader->hashUTF8->lookupOrCreateReader(buf, n);
     ctpRes[entry] = (UTF8*)utf8;
   
-    PRINT_DEBUG(JNJVM_LOAD, 3, COLOR_NORMAL, "; [%5d] <utf8>\t\t\"%s\"\n", entry,
-                utf8->printString());
+    PRINT_DEBUG(JNJVM_LOAD, 3, COLOR_NORMAL, "; [%5d] <utf8>\t\t\"%s\"\n",
+                entry, UTF8Buffer(utf8)->cString());
 
   }
   return (const UTF8*)ctpRes[entry];
@@ -227,7 +228,8 @@
 
 float JavaConstantPool::FloatAt(uint32 entry) {
   if (!((entry > 0) && (entry < ctpSize) && typeAt(entry) == ConstantFloat)) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   return ((float*)ctpDef)[entry];
@@ -235,7 +237,8 @@
 
 sint32 JavaConstantPool::IntegerAt(uint32 entry) {
   if (!((entry > 0) && (entry < ctpSize) && typeAt(entry) == ConstantInteger)) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   return ((sint32*)ctpDef)[entry];
@@ -243,7 +246,8 @@
 
 sint64 JavaConstantPool::LongAt(uint32 entry) {
   if (!((entry > 0) && (entry < ctpSize) && typeAt(entry) == ConstantLong)) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   return Reader::readLong(ctpDef[entry], ctpDef[entry + 1]);
@@ -251,7 +255,8 @@
 
 double JavaConstantPool::DoubleAt(uint32 entry) {
   if (!((entry > 0) && (entry < ctpSize) && typeAt(entry) == ConstantDouble)) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   return Reader::readDouble(ctpDef[entry], ctpDef[entry + 1]);
@@ -259,7 +264,8 @@
 
 CommonClass* JavaConstantPool::isClassLoaded(uint32 entry) {
   if (!((entry > 0) && (entry < ctpSize) &&  typeAt(entry) == ConstantClass)) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   return (CommonClass*)ctpRes[entry];
@@ -310,7 +316,8 @@
   void* res = ctpRes[index];
   if (!res) {
     if (typeAt(index) != ConstantNameAndType) {
-      fprintf(stderr, "Malformed class %s\n", classDef->printString());
+      fprintf(stderr, "Malformed class %s\n",
+              UTF8Buffer(classDef->name).cString());
       abort();
     }
     sint32 entry = ctpDef[index];
@@ -326,7 +333,8 @@
   void* res = ctpRes[index];
   if (!res) {
     if (typeAt(index) != ConstantNameAndType) {
-      fprintf(stderr, "Malformed class %s\n", classDef->printString());
+      fprintf(stderr, "Malformed class %s\n",
+              UTF8Buffer(classDef->name).cString());
       abort();
     }
     sint32 entry = ctpDef[index];
@@ -340,7 +348,8 @@
 
 Typedef* JavaConstantPool::infoOfField(uint32 index) {
   if (typeAt(index) != ConstantFieldref) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
 
@@ -351,7 +360,7 @@
                                     CommonClass*& cl, JavaMethod*& meth) {
   uint8 id = typeAt(index);
   if (id != ConstantMethodref && id != ConstantInterfaceMethodref) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n", UTF8Buffer(classDef->name).cString());
     abort();
   }
   
@@ -390,7 +399,8 @@
                                               Signdef*& sign) {
   uint8 id = typeAt(index);
   if (id != ConstantMethodref && id != ConstantInterfaceMethodref) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   
@@ -406,7 +416,8 @@
                                                           Signdef* sign) {
   uint8 id = typeAt(index);
   if (id != ConstantMethodref && id != ConstantInterfaceMethodref) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   
@@ -433,7 +444,8 @@
 
   uint8 id = typeAt(index);
   if (id != ConstantMethodref && id != ConstantInterfaceMethodref) {
-    fprintf(stderr, "Malformed class %s\n", classDef->printString());
+    fprintf(stderr, "Malformed class %s\n",
+            UTF8Buffer(classDef->name).cString());
     abort();
   }
   

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sun May 17 09:05:45 2009
@@ -602,18 +602,23 @@
 }
 
 extern "C" void jnjvmPrintMethodStart(JavaMethod* meth) {
-  fprintf(stderr, "[%p] executing %s\n", (void*)mvm::Thread::get(),
-         meth->printString());
+  fprintf(stderr, "[%p] executing %s.%s\n", (void*)mvm::Thread::get(),
+          UTF8Buffer(meth->classDef->name).cString(),
+          UTF8Buffer(meth->name).cString());
 }
 
 extern "C" void jnjvmPrintMethodEnd(JavaMethod* meth) {
-  fprintf(stderr, "[%p] return from %s\n", (void*)mvm::Thread::get(),
-         meth->printString());
+  fprintf(stderr, "[%p] return from %s.%s\n", (void*)mvm::Thread::get(),
+          UTF8Buffer(meth->classDef->name).cString(),
+          UTF8Buffer(meth->name).cString());
 }
 
-extern "C" void jnjvmPrintExecution(uint32 opcode, uint32 index, JavaMethod* meth) {
-  fprintf(stderr, "[%p] executing %s %s at %d\n", (void*)mvm::Thread::get(),
-         meth->printString(), OpcodeNames[opcode], index);
+extern "C" void jnjvmPrintExecution(uint32 opcode, uint32 index,
+                                    JavaMethod* meth) {
+  fprintf(stderr, "[%p] executing %s.%s %s at %d\n", (void*)mvm::Thread::get(),
+         UTF8Buffer(meth->classDef->name).cString(),
+         UTF8Buffer(meth->name).cString(),
+         OpcodeNames[opcode], index);
 }
 
 #ifdef SERVICE

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp Sun May 17 09:05:45 2009
@@ -38,12 +38,12 @@
 }
 
 char* JavaString::strToAsciiz() {
-  mvm::NativeString* buf = mvm::NativeString::alloc(count + 1); 
+  char* buf = new char[count + 1]; 
   for (sint32 i = 0; i < count; ++i) {
-    buf->setAt(i, value->elements[i + offset]);
+    buf[i] = value->elements[i + offset];
   }
-  buf->setAt(count, 0); 
-  return buf->cString();
+  buf[count] =  0; 
+  return buf;
 }
 
 const ArrayUInt16* JavaString::strToArray(Jnjvm* vm) {

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Sun May 17 09:05:45 2009
@@ -7,7 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "mvm/PrintBuffer.h"
 #include "mvm/Threads/Locks.h"
 #include "mvm/Threads/Thread.h"
 
@@ -216,7 +215,9 @@
        i != e; ++i) {
     JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
     assert(meth && "Wrong stack");
-    fprintf(stderr, "; %p in %s\n",  *i, meth->printString());
+    fprintf(stderr, "; %p in %s.%s\n",  *i,
+            UTF8Buffer(meth->classDef->name).cString(),
+            UTF8Buffer(meth->name).cString());
   }
 }
 
@@ -257,7 +258,9 @@
       void* ip = FRAME_IP(addr);
       JavaMethod* meth = vm->IPToMethod<JavaMethod>(ip);
       assert(meth && "Wrong stack");
-      fprintf(stderr, "; %p in %s\n",  ip, meth->printString());
+      fprintf(stderr, "; %p in %s.%s\n",  ip,
+              UTF8Buffer(meth->classDef->name).cString(),
+              UTF8Buffer(meth->name).cString());
       addr = (void**)addr[0];
       // End walking the stack when we cross a native -> Java call. Here
       // the iterator points to a native -> Java call. We dereference addr twice

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h Sun May 17 09:05:45 2009
@@ -65,13 +65,6 @@
   ///
   const UTF8* keyName;
   
-  /// printString - Print the Typedef for debugging purposes.
-  ///
-  const char* printString() const {
-    assert(keyName && "No key name");
-    return keyName->printString();
-  }
-  
   /// assocClass - Given the loaded, try to load the class represented by this
   /// Typedef.
   ///
@@ -269,12 +262,6 @@
   ///
   const UTF8* keyName;
   
-  /// printString - Print the signature with the following extension.
-  ///
-  const char* printString() const {
-    return keyName->printString();
-  }
-  
   /// nativeName - Get a native name for callbacks emitted AOT.
   ///
   void nativeName(char* buf, const char* ext) const;

Modified: vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp Sun May 17 09:05:45 2009
@@ -1981,7 +1981,7 @@
   BEGIN_JNI_EXCEPTION
 
   if (isCopy != 0) (*isCopy) = true;
-  return strdup(((JavaString*)string)->strToAsciiz());
+  return ((JavaString*)string)->strToAsciiz();
 
   END_JNI_EXCEPTION
   return 0;
@@ -1989,7 +1989,7 @@
 
 
 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf) {
-  free((void*)utf);
+  delete[] utf;
 }
 
 

Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun May 17 09:05:45 2009
@@ -620,20 +620,16 @@
 }
 
 JavaString* Jnjvm::internalUTF8ToStr(const UTF8* utf8) {
-  JavaString* res = hashStr.lookup(utf8);
-  if (!res) {
-    uint32 size = utf8->size;
-    ArrayUInt16* tmp = (ArrayUInt16*)upcalls->ArrayOfChar->doNew(size, this);
-    uint16* buf = tmp->elements;
-  
-    for (uint32 i = 0; i < size; i++) {
-      buf[i] = utf8->elements[i];
-    }
+  uint32 size = utf8->size;
+  ArrayUInt16* tmp = (ArrayUInt16*)upcalls->ArrayOfChar->doNew(size, this);
+  uint16* buf = tmp->elements;
   
-    res = hashStr.lookupOrCreate((const ArrayUInt16*&)tmp, this,
-                                 JavaString::stringDup);
+  for (uint32 i = 0; i < size; i++) {
+    buf[i] = utf8->elements[i];
   }
-  return res;
+  
+  return hashStr.lookupOrCreate((const ArrayUInt16*&)tmp, this,
+                                JavaString::stringDup);
 }
 
 JavaString* Jnjvm::constructString(const ArrayUInt16* array) { 
@@ -925,10 +921,6 @@
 }
 
 
-void Jnjvm::print(mvm::PrintBuffer* buf) const {
-  buf->write("Java isolate");
-}
-
 JnjvmClassLoader* Jnjvm::loadAppClassLoader() {
   if (appClassLoader == 0) {
     UserClass* cl = upcalls->newClassLoader;

Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sun May 17 09:05:45 2009
@@ -16,7 +16,6 @@
 
 #include "mvm/Allocator.h"
 #include "mvm/Object.h"
-#include "mvm/PrintBuffer.h"
 #include "mvm/VirtualMachine.h"
 #include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
@@ -167,10 +166,6 @@
 
 public:
   
-  /// print - Prints the JVM for debugging purposes.
-  ///
-  virtual void print(mvm::PrintBuffer* buf) const;
-
   /// tracer - Traces instances of this class.
   ///
   virtual void TRACER;

Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sun May 17 09:05:45 2009
@@ -294,8 +294,12 @@
 }
 
 ArrayUInt8* JnjvmBootstrapLoader::openName(const UTF8* utf8) {
-  char* asciiz = utf8->printString();
-  uint32 alen = strlen(asciiz);
+  char* asciiz = (char*)alloca(utf8->size + 1);
+  for (sint32 i = 0; i < utf8->size; ++i) 
+    asciiz[i] = utf8->elements[i];
+  asciiz[utf8->size] = 0;
+  
+  uint32 alen = utf8->size;
   ArrayUInt8* res = 0;
   
   for (std::vector<const char*>::iterator i = bootClasspath.begin(),
@@ -687,9 +691,9 @@
 
 static void typeError(const UTF8* name, short int l) {
   if (l != 0) {
-    fprintf(stderr, "wrong type %d in %s", l, name->printString());
+    fprintf(stderr, "wrong type %d in %s", l, UTF8Buffer(name).cString());
   } else {
-    fprintf(stderr, "wrong type %s", name->printString());
+    fprintf(stderr, "wrong type %s", UTF8Buffer(name).cString());
   }
   abort();
 }

Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h?rev=71978&r1=71977&r2=71978&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Sun May 17 09:05:45 2009
@@ -23,7 +23,6 @@
 #include "types.h"
 
 #include "mvm/Allocator.h"
-#include "mvm/PrintBuffer.h"
 #include "mvm/Threads/Locks.h"
 
 #include "JavaArray.h" // for comparing UTF8s
@@ -48,7 +47,10 @@
 {
   bool operator()(const ArrayUInt16* s1, const ArrayUInt16* s2) const
   {
-    return ((UTF8*)s1)->lessThan((UTF8*)s2);
+    if (s1->size < s2->size) return true;
+    else if (s1->size > s2->size) return false;
+    else return memcmp((const char*)s1->elements, (const char*)s2->elements,
+                       s1->size * sizeof(uint16)) < 0;
   }
 };
 





More information about the vmkit-commits mailing list