[vmkit-commits] [vmkit] r56976 - in /vmkit/branches/isolate/lib/JnJVM/VMCore: JavaArray.cpp JavaArray.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Oct 2 15:57:26 PDT 2008


Author: geoffray
Date: Thu Oct  2 17:57:26 2008
New Revision: 56976

URL: http://llvm.org/viewvc/llvm-project?rev=56976&view=rev
Log:
Implement UTF8::checkedJavaToInternal, UTF8::printString, and malloc
instead of gcmalloc when debugging UTF8ToAsciiz.


Modified:
    vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.cpp
    vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.h

Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.cpp?rev=56976&r1=56975&r2=56976&view=diff

==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.cpp (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.cpp Thu Oct  2 17:57:26 2008
@@ -88,6 +88,19 @@
   return map->lookupOrCreateReader(java, len);
 }
 
+const UTF8* UTF8::checkedJavaToInternal(UTF8Map* map, unsigned int start,
+                                        unsigned int len) const {
+  uint16* java = (uint16*) alloca(len * sizeof(uint16));
+  for (uint32 i = 0; i < len; i++) {
+    uint16 cur = elements[start + i];
+    if (cur == '.') java[i] = '/';
+    else if (cur == '/') return 0;
+    else java[i] = cur;
+  }
+
+  return map->lookupOrCreateReader(java, len);
+}
+
 const UTF8* UTF8::internalToJava(UTF8Map* map, unsigned int start,
                                  unsigned int len) const {
   uint16* java = (uint16*) alloca(len * sizeof(uint16));
@@ -112,12 +125,21 @@
 }
 
 char* UTF8::UTF8ToAsciiz() 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
+  char* buf = (char*)malloc(size + 1);
+  for (sint32 i = 0; i < size; ++i) {
+    buf[i] =  elements[i];
+  }
+  buf[size] = 0;
+  return buf;
+#endif
 }
 
 /// Currently, this uses malloc/free. This should use a custom memory pool.

Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.h?rev=56976&r1=56975&r2=56976&view=diff

==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaArray.h Thu Oct  2 17:57:26 2008
@@ -137,8 +137,18 @@
   const UTF8* javaToInternal(UTF8Map* map, unsigned int start,
                              unsigned int len) const;
   
+  /// checkedJavaToInternal - Replaces all '/' into '.'. Returns null if the
+  /// UTF8 contains a '/', as Java does not allow things like
+  /// Class.forName("java/lang/Object")
+  const UTF8* checkedJavaToInternal(UTF8Map* map, unsigned int start,
+                                    unsigned int len) const;
+  
   /// UTF8ToAsciiz - Allocates a C string with the contents of this UTF8.
   char* UTF8ToAsciiz() const;
+  
+  char* printString() const {
+    return UTF8ToAsciiz();
+  }
 
   /// extract - Creates an UTF8 by extracting the contents at the given size
   /// of this.





More information about the vmkit-commits mailing list