[vmkit-commits] [vmkit] r83269 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h include/mvm/UTF8.h lib/JnJVM/Compiler/JavaJIT.h lib/JnJVM/VMCore/JavaArray.cpp lib/JnJVM/VMCore/JavaArray.h lib/JnJVM/VMCore/JavaCache.h lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/JavaConstantPool.h lib/JnJVM/VMCore/JavaString.h lib/JnJVM/VMCore/JavaTypes.h lib/JnJVM/VMCore/Jnjvm.h lib/JnJVM/VMCore/JnjvmClassLoader.h lib/JnJVM/VMCore/LockedMap.cpp lib/JnJVM/VMCore/LockedMap.h lib/JnJVM/VMCore/UTF8.h lib/Mvm/Runtime/UTF8.cpp
Gael Thomas
gael.thomas at lip6.fr
Sat Oct 3 11:13:47 PDT 2009
Author: gthomas
Date: Sat Oct 3 13:13:46 2009
New Revision: 83269
URL: http://llvm.org/viewvc/llvm-project?rev=83269&view=rev
Log:
Remove UTF8 from JnJVM and put it in Mvm. It will be usefull for N3.
JnJVM uses now mvm::UTF8 (mvm::UTF8 is also linked to jnjvm::UTF8).
Added:
vmkit/trunk/include/mvm/UTF8.h
vmkit/trunk/lib/JnJVM/VMCore/UTF8.h
vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp
Modified:
vmkit/trunk/include/jnjvm/JnjvmModule.h
vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h
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.h
vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h
vmkit/trunk/lib/JnJVM/VMCore/JavaString.h
vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp
vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sat Oct 3 13:13:46 2009
@@ -15,6 +15,7 @@
#include "mvm/Allocator.h"
#include "mvm/JIT.h"
+#include "mvm/UTF8.h"
#include "JavaCompiler.h"
@@ -52,7 +53,8 @@
class JnjvmModule;
class Typedef;
class Signdef;
-class UTF8;
+
+using mvm::UTF8;
class LLVMAssessorInfo {
public:
Added: vmkit/trunk/include/mvm/UTF8.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=83269&view=auto
==============================================================================
--- vmkit/trunk/include/mvm/UTF8.h (added)
+++ vmkit/trunk/include/mvm/UTF8.h Sat Oct 3 13:13:46 2009
@@ -0,0 +1,137 @@
+#ifndef _UTF8_INTERNAL_H_
+#define _UTF8_INTERNAL_H_
+
+#include <map>
+#include "mvm/Allocator.h"
+
+namespace mvm {
+
+class UTF8Map;
+
+class UTF8 {
+ friend class UTF8Map;
+private:
+
+ /// operator new - Redefines the new operator of this class to allocate
+ /// 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(ssize_t) + size * sizeof(uint16), "UTF8");
+ }
+
+ UTF8(sint32 n) {
+ size = n;
+ }
+
+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;
+
+ /// equals - Are the two UTF8s equal?
+ bool equals(const UTF8* other) const {
+ if (other == this) return true;
+ else if (size != other->size) return false;
+ else return !memcmp(elements, other->elements, size * sizeof(uint16));
+ }
+
+ /// equals - Does the UTF8 equal to the buffer?
+ bool equals(const uint16* buf, sint32 len) const {
+ if (size != len) return false;
+ else return !memcmp(elements, buf, size * sizeof(uint16));
+ }
+
+ /// lessThan - strcmp-like function for UTF8s, used by hash tables.
+ bool lessThan(const UTF8* other) const {
+ if (size < other->size) return true;
+ else if (size > other->size) return false;
+ else return memcmp((const char*)elements, (const char*)other->elements,
+ size * sizeof(uint16)) < 0;
+ }
+
+};
+
+
+class UTF8Map : public mvm::PermanentObject {
+private:
+ typedef std::multimap<const uint32, const UTF8*>::iterator iterator;
+
+ mvm::LockNormal lock;
+ mvm::BumpPtrAllocator& allocator;
+ std::multimap<const uint32, const UTF8*> map;
+public:
+
+ const UTF8* lookupOrCreateAsciiz(const char* asciiz);
+ const UTF8* lookupOrCreateReader(const uint16* buf, uint32 size);
+ const UTF8* lookupAsciiz(const char* asciiz);
+ const UTF8* lookupReader(const uint16* buf, uint32 size);
+
+ UTF8Map(mvm::BumpPtrAllocator& A) : allocator(A) {}
+
+ ~UTF8Map() {
+ for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
+ allocator.Deallocate((void*)i->second);
+ }
+ }
+
+ void copy(UTF8Map* newMap) {
+ for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
+ newMap->map.insert(*i);
+ }
+ }
+
+ void replace(const UTF8* oldUTF8, const UTF8* newUTF8);
+ void insert(const UTF8* val);
+};
+
+/// 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 + 1];
+ for (sint32 i = 0; i < val->size; ++i)
+ buffer[i] = val->elements[i];
+ buffer[val->size] = 0;
+ }
+
+ /// ~UTF8Buffer - Delete the buffer, as well as all dynamically
+ /// allocated memory.
+ ///
+ ~UTF8Buffer() {
+ delete[] buffer;
+ }
+
+ /// replaceWith - replace the content of the buffer and free the old buffer
+ ///
+ void replaceWith(char *buffer) {
+ delete[] this->buffer;
+ this->buffer = buffer;
+ }
+
+
+ /// cString - Return a C string representation of the buffer, suitable
+ /// for printf.
+ ///
+ const char* cString() {
+ return buffer;
+ }
+};
+
+} // end namespace mvm
+
+#endif
Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h Sat Oct 3 13:13:46 2009
@@ -31,7 +31,6 @@
class JavaMethod;
class JnjvmModule;
class Reader;
-class UTF8;
/// Opinfo - This class gives for each opcode if it starts a new block and
/// its exception destination.
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp Sat Oct 3 13:13:46 2009
@@ -34,14 +34,3 @@
const unsigned int JavaArray::T_SHORT = 9;
const unsigned int JavaArray::T_INT = 10;
const unsigned int JavaArray::T_LONG = 11;
-
-const UTF8* UTF8::extract(UTF8Map* map, uint32 start, uint32 end) const {
- uint32 len = end - start;
- uint16* buf = (uint16*)alloca(sizeof(uint16) * len);
-
- for (uint32 i = 0; i < len; i++) {
- buf[i] = elements[i + start];
- }
-
- return map->lookupOrCreateReader(buf, len);
-}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Sat Oct 3 13:13:46 2009
@@ -20,13 +20,14 @@
#include "JavaObject.h"
+#include "UTF8.h"
+
namespace jnjvm {
class ClassArray;
class CommonClass;
class JavaObject;
class Jnjvm;
-class UTF8Map;
/// TJavaArray - Template class to be instantiated by real arrays. All arrays
/// have a constant size and an array of element. When JnJVM allocates an
@@ -85,127 +86,6 @@
#undef ARRAYCLASS
-/// UTF8 - The UTF8 class is basically the ArrayUInt16 class (arrays of elements
-/// 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 {
- friend class UTF8Map;
-private:
-
- /// operator new - Redefines the new operator of this class to allocate
- /// 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(ssize_t) + size * sizeof(uint16), "UTF8");
- }
-
- UTF8(sint32 n) {
- size = n;
- }
-
-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;
-
- /// equals - Are the two UTF8s equal?
- bool equals(const UTF8* other) const {
- if (other == this) return true;
- else if (size != other->size) return false;
- else return !memcmp(elements, other->elements, size * sizeof(uint16));
- }
-
- /// equals - Does the UTF8 equal to the buffer?
- bool equals(const uint16* buf, sint32 len) const {
- if (size != len) return false;
- else return !memcmp(elements, buf, size * sizeof(uint16));
- }
-
- /// lessThan - strcmp-like function for UTF8s, used by hash tables.
- bool lessThan(const UTF8* other) const {
- if (size < other->size) return true;
- else if (size > other->size) return false;
- else return memcmp((const char*)elements, (const char*)other->elements,
- size * sizeof(uint16)) < 0;
- }
-
-};
-
-
-/// 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 + 1];
- for (sint32 i = 0; i < val->size; ++i)
- buffer[i] = val->elements[i];
- buffer[val->size] = 0;
- }
-
- /// ~UTF8Buffer - Delete the buffer, as well as all dynamically
- /// allocated memory.
- ///
- ~UTF8Buffer() {
- delete[] buffer;
- }
-
- /// toCompileName - Change the utf8 following JNI conventions.
- ///
- UTF8Buffer* toCompileName() {
- uint32 len = strlen(buffer);
- char* newBuffer = new char[(len << 1) + 1];
- uint32 j = 0;
- for (uint32 i = 0; i < len; ++i) {
- if (buffer[i] == '/') {
- newBuffer[j++] = '_';
- } else if (buffer[i] == '_') {
- newBuffer[j++] = '_';
- newBuffer[j++] = '1';
- } else if (buffer[i] == ';') {
- newBuffer[j++] = '_';
- newBuffer[j++] = '2';
- } else if (buffer[i] == '[') {
- newBuffer[j++] = '_';
- newBuffer[j++] = '3';
- } else if (buffer[i] == '$') {
- newBuffer[j++] = '_';
- newBuffer[j++] = '4';
- } else {
- newBuffer[j++] = buffer[i];
- }
- }
- newBuffer[j] = 0;
- delete[] buffer;
- buffer = newBuffer;
- return this;
- }
-
- /// 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=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h Sat Oct 3 13:13:46 2009
@@ -28,12 +28,12 @@
#include "types.h"
#include "JnjvmConfig.h"
+#include "UTF8.h"
namespace jnjvm {
class Enveloppe;
class JavaVirtualTable;
-class UTF8;
/// CacheNode - A {class, method pointer} pair.
class CacheNode : public mvm::PermanentObject {
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Oct 3 13:13:46 2009
@@ -42,7 +42,6 @@
class Reader;
class Signdef;
class Typedef;
-class UTF8;
/// JavaState - List of states a Java class can have. A class is ready to be
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h Sat Oct 3 13:13:46 2009
@@ -24,7 +24,6 @@
class Reader;
class Signdef;
class Typedef;
-class UTF8;
/// JavaConstantPool - This class represents a Java constant pool, a place where
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaString.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaString.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaString.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaString.h Sat Oct 3 13:13:46 2009
@@ -18,8 +18,6 @@
class ArrayUInt16;
class Jnjvm;
-class UTF8;
-class UTF8Map;
class JavaString : public JavaObject {
public:
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h Sat Oct 3 13:13:46 2009
@@ -21,8 +21,6 @@
class UserCommonClass;
class JnjvmClassLoader;
class UserClassPrimitive;
-class UTF8;
-class UTF8Map;
#define VOID_ID 0
#define BOOL_ID 1
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sat Oct 3 13:13:46 2009
@@ -41,7 +41,6 @@
class UserClassArray;
class UserClassPrimitive;
class UserCommonClass;
-class UTF8;
/// ThreadSystem - Thread management of a JVM. Each JVM has one thread
/// management system to count the number of non-daemon threads it owns.
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Sat Oct 3 13:13:46 2009
@@ -16,6 +16,8 @@
#include "types.h"
+#include "UTF8.h"
+
#include "mvm/Allocator.h"
#include "mvm/Object.h"
@@ -41,8 +43,6 @@
class StringList;
class Typedef;
class TypeMap;
-class UTF8;
-class UTF8Map;
class ZipArchive;
Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp Sat Oct 3 13:13:46 2009
@@ -20,157 +20,6 @@
using namespace jnjvm;
-
-static uint32 asciizHasher(const char* asciiz, sint32 size) {
- uint32 r0 = 0, r1 = 0;
- for (sint32 i = 0; i < size; i++) {
- char c = asciiz[i];
- r0 += c;
- r1 ^= c;
- }
- return (r1 & 255) + ((r0 & 255) << 8);
-}
-
-static uint32 readerHasher(const uint16* buf, sint32 size) {
- uint32 r0 = 0, r1 = 0;
- for (sint32 i = 0; i < size; i++) {
- uint16 c = buf[i];
- r0 += c;
- r1 ^= c;
- }
- return (r1 & 255) + ((r0 & 255) << 8);
-}
-
-static bool asciizEqual(const UTF8* val, const char* asciiz, sint32 size) {
- sint32 len = val->size;
- if (len != size) return false;
- else {
- for (sint32 i = 0; i < len; i++) {
- if (asciiz[i] != val->elements[i]) return false;
- }
- return true;
- }
-}
-
-static bool readerEqual(const UTF8* val, const uint16* buf, sint32 size) {
- sint32 len = val->size;
- if (len != size) return false;
- else return !(memcmp(val->elements, buf, len * sizeof(uint16)));
-}
-
-void UTF8Map::replace(const UTF8* oldUTF8, const UTF8* newUTF8) {
- lock.lock();
- uint32 key = readerHasher(oldUTF8->elements, oldUTF8->size);
- std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
-
- for (UTF8Map::iterator i = p.first; i != p.second; i++) {
- if (i->second == oldUTF8) {
- map.erase(i);
- break;
- }
- }
- map.insert(std::make_pair(key, newUTF8));
- lock.unlock();
-
-}
-
-const UTF8* UTF8Map::lookupOrCreateAsciiz(const char* asciiz) {
- sint32 size = strlen(asciiz);
- uint32 key = asciizHasher(asciiz, size);
- const UTF8* res = 0;
- lock.lock();
-
- std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
-
- for (UTF8Map::iterator i = p.first; i != p.second; i++) {
- if (asciizEqual(i->second, asciiz, size)) {
- res = i->second;
- break;
- }
- }
-
- if (res == 0) {
- UTF8* tmp = new(allocator, size) UTF8(size);
- for (sint32 i = 0; i < size; i++) {
- tmp->elements[i] = asciiz[i];
- }
- res = (const UTF8*)tmp;
- map.insert(std::make_pair(key, res));
- }
-
- lock.unlock();
- return res;
-}
-
-const UTF8* UTF8Map::lookupOrCreateReader(const uint16* buf, uint32 len) {
- sint32 size = (sint32)len;
- uint32 key = readerHasher(buf, size);
- const UTF8* res = 0;
- lock.lock();
-
- std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
-
- for (UTF8Map::iterator i = p.first; i != p.second; i++) {
- if (readerEqual(i->second, buf, size)) {
- res = i->second;
- break;
- }
- }
-
- if (res == 0) {
- UTF8* tmp = new(allocator, size) UTF8(size);
- memcpy(tmp->elements, buf, len * sizeof(uint16));
- res = (const UTF8*)tmp;
- map.insert(std::make_pair(key, res));
- }
-
- lock.unlock();
- return res;
-}
-
-const UTF8* UTF8Map::lookupAsciiz(const char* asciiz) {
- sint32 size = strlen(asciiz);
- uint32 key = asciizHasher(asciiz, size);
- const UTF8* res = 0;
- lock.lock();
-
- std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
-
- for (UTF8Map::iterator i = p.first; i != p.second; i++) {
- if (asciizEqual(i->second, asciiz, size)) {
- res = i->second;
- break;
- }
- }
-
- lock.unlock();
- return res;
-}
-
-const UTF8* UTF8Map::lookupReader(const uint16* buf, uint32 len) {
- sint32 size = (sint32)len;
- uint32 key = readerHasher(buf, size);
- const UTF8* res = 0;
- lock.lock();
-
- std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
-
- for (UTF8Map::iterator i = p.first; i != p.second; i++) {
- if (readerEqual(i->second, buf, size)) {
- res = i->second;
- break;
- }
- }
-
- lock.unlock();
- return res;
-}
-
-
-void UTF8Map::insert(const UTF8* val) {
- map.insert(std::make_pair(readerHasher(val->elements, val->size), val));
-}
-
void StringMap::insert(JavaString* str) {
map.insert(std::make_pair(str->value, str));
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h?rev=83269&r1=83268&r2=83269&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Sat Oct 3 13:13:46 2009
@@ -24,6 +24,7 @@
#include "mvm/Allocator.h"
#include "mvm/Threads/Locks.h"
+#include "UTF8.h"
#include "JavaArray.h" // for comparing UTF8s
@@ -116,36 +117,6 @@
~LockedMap() {}
};
-class UTF8Map : public mvm::PermanentObject {
-public:
- typedef std::multimap<const uint32, const UTF8*>::iterator iterator;
-
- mvm::LockNormal lock;
- mvm::BumpPtrAllocator& allocator;
- std::multimap<const uint32, const UTF8*> map;
- const UTF8* lookupOrCreateAsciiz(const char* asciiz);
- const UTF8* lookupOrCreateReader(const uint16* buf, uint32 size);
- const UTF8* lookupAsciiz(const char* asciiz);
- const UTF8* lookupReader(const uint16* buf, uint32 size);
-
- UTF8Map(mvm::BumpPtrAllocator& A) : allocator(A) {}
-
- ~UTF8Map() {
- for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
- allocator.Deallocate((void*)i->second);
- }
- }
-
- void copy(UTF8Map* newMap) {
- for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
- newMap->map.insert(*i);
- }
- }
-
- void replace(const UTF8* oldUTF8, const UTF8* newUTF8);
- void insert(const UTF8* val);
-};
-
class ClassMap :
public LockedMap<const UTF8*, UserCommonClass*, ltutf8, JnjvmClassLoader*,
mvm::LockRecursive > {
Added: vmkit/trunk/lib/JnJVM/VMCore/UTF8.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/UTF8.h?rev=83269&view=auto
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/UTF8.h (added)
+++ vmkit/trunk/lib/JnJVM/VMCore/UTF8.h Sat Oct 3 13:13:46 2009
@@ -0,0 +1,54 @@
+#ifndef _JNJVM_UTF8_H_
+#define _JNJVM_UTF8_H_
+
+#include "types.h"
+
+#include "mvm/UTF8.h"
+
+namespace jnjvm {
+ using mvm::UTF8;
+ using mvm::UTF8Map;
+
+/// UTF8Buffer - Helper class to create char* buffers suitable for
+/// printf.
+///
+class UTF8Buffer : public mvm::UTF8Buffer {
+public:
+ /// UTF8Buffer - Create a buffer with the following UTF8.
+ UTF8Buffer(const UTF8* val) : mvm::UTF8Buffer(val) {}
+
+ /// toCompileName - Change the utf8 following JNI conventions.
+ ///
+ UTF8Buffer* toCompileName() {
+ const char *buffer = cString();
+ uint32 len = strlen(buffer);
+ char* newBuffer = new char[(len << 1) + 1];
+ uint32 j = 0;
+ for (uint32 i = 0; i < len; ++i) {
+ if (buffer[i] == '/') {
+ newBuffer[j++] = '_';
+ } else if (buffer[i] == '_') {
+ newBuffer[j++] = '_';
+ newBuffer[j++] = '1';
+ } else if (buffer[i] == ';') {
+ newBuffer[j++] = '_';
+ newBuffer[j++] = '2';
+ } else if (buffer[i] == '[') {
+ newBuffer[j++] = '_';
+ newBuffer[j++] = '3';
+ } else if (buffer[i] == '$') {
+ newBuffer[j++] = '_';
+ newBuffer[j++] = '4';
+ } else {
+ newBuffer[j++] = buffer[i];
+ }
+ }
+ newBuffer[j] = 0;
+ replaceWith(newBuffer);
+ return this;
+ }
+};
+
+}
+
+#endif
Added: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=83269&view=auto
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (added)
+++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Sat Oct 3 13:13:46 2009
@@ -0,0 +1,163 @@
+#include "mvm/UTF8.h"
+
+using namespace mvm;
+
+const UTF8* UTF8::extract(UTF8Map* map, uint32 start, uint32 end) const {
+ uint32 len = end - start;
+ uint16* buf = (uint16*)alloca(sizeof(uint16) * len);
+
+ for (uint32 i = 0; i < len; i++) {
+ buf[i] = elements[i + start];
+ }
+
+ return map->lookupOrCreateReader(buf, len);
+}
+
+static uint32 asciizHasher(const char* asciiz, sint32 size) {
+ uint32 r0 = 0, r1 = 0;
+ for (sint32 i = 0; i < size; i++) {
+ char c = asciiz[i];
+ r0 += c;
+ r1 ^= c;
+ }
+ return (r1 & 255) + ((r0 & 255) << 8);
+}
+
+static uint32 readerHasher(const uint16* buf, sint32 size) {
+ uint32 r0 = 0, r1 = 0;
+ for (sint32 i = 0; i < size; i++) {
+ uint16 c = buf[i];
+ r0 += c;
+ r1 ^= c;
+ }
+ return (r1 & 255) + ((r0 & 255) << 8);
+}
+
+static bool asciizEqual(const UTF8* val, const char* asciiz, sint32 size) {
+ sint32 len = val->size;
+ if (len != size) return false;
+ else {
+ for (sint32 i = 0; i < len; i++) {
+ if (asciiz[i] != val->elements[i]) return false;
+ }
+ return true;
+ }
+}
+
+static bool readerEqual(const UTF8* val, const uint16* buf, sint32 size) {
+ sint32 len = val->size;
+ if (len != size) return false;
+ else return !(memcmp(val->elements, buf, len * sizeof(uint16)));
+}
+
+void UTF8Map::replace(const UTF8* oldUTF8, const UTF8* newUTF8) {
+ lock.lock();
+ uint32 key = readerHasher(oldUTF8->elements, oldUTF8->size);
+ std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
+
+ for (UTF8Map::iterator i = p.first; i != p.second; i++) {
+ if (i->second == oldUTF8) {
+ map.erase(i);
+ break;
+ }
+ }
+ map.insert(std::make_pair(key, newUTF8));
+ lock.unlock();
+
+}
+
+const UTF8* UTF8Map::lookupOrCreateAsciiz(const char* asciiz) {
+ sint32 size = strlen(asciiz);
+ uint32 key = asciizHasher(asciiz, size);
+ const UTF8* res = 0;
+ lock.lock();
+
+ std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
+
+ for (UTF8Map::iterator i = p.first; i != p.second; i++) {
+ if (asciizEqual(i->second, asciiz, size)) {
+ res = i->second;
+ break;
+ }
+ }
+
+ if (res == 0) {
+ UTF8* tmp = new(allocator, size) UTF8(size);
+ for (sint32 i = 0; i < size; i++) {
+ tmp->elements[i] = asciiz[i];
+ }
+ res = (const UTF8*)tmp;
+ map.insert(std::make_pair(key, res));
+ }
+
+ lock.unlock();
+ return res;
+}
+
+const UTF8* UTF8Map::lookupOrCreateReader(const uint16* buf, uint32 len) {
+ sint32 size = (sint32)len;
+ uint32 key = readerHasher(buf, size);
+ const UTF8* res = 0;
+ lock.lock();
+
+ std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
+
+ for (UTF8Map::iterator i = p.first; i != p.second; i++) {
+ if (readerEqual(i->second, buf, size)) {
+ res = i->second;
+ break;
+ }
+ }
+
+ if (res == 0) {
+ UTF8* tmp = new(allocator, size) UTF8(size);
+ memcpy(tmp->elements, buf, len * sizeof(uint16));
+ res = (const UTF8*)tmp;
+ map.insert(std::make_pair(key, res));
+ }
+
+ lock.unlock();
+ return res;
+}
+
+const UTF8* UTF8Map::lookupAsciiz(const char* asciiz) {
+ sint32 size = strlen(asciiz);
+ uint32 key = asciizHasher(asciiz, size);
+ const UTF8* res = 0;
+ lock.lock();
+
+ std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
+
+ for (UTF8Map::iterator i = p.first; i != p.second; i++) {
+ if (asciizEqual(i->second, asciiz, size)) {
+ res = i->second;
+ break;
+ }
+ }
+
+ lock.unlock();
+ return res;
+}
+
+const UTF8* UTF8Map::lookupReader(const uint16* buf, uint32 len) {
+ sint32 size = (sint32)len;
+ uint32 key = readerHasher(buf, size);
+ const UTF8* res = 0;
+ lock.lock();
+
+ std::pair<UTF8Map::iterator, UTF8Map::iterator> p = map.equal_range(key);
+
+ for (UTF8Map::iterator i = p.first; i != p.second; i++) {
+ if (readerEqual(i->second, buf, size)) {
+ res = i->second;
+ break;
+ }
+ }
+
+ lock.unlock();
+ return res;
+}
+
+void UTF8Map::insert(const UTF8* val) {
+ map.insert(std::make_pair(readerHasher(val->elements, val->size), val));
+}
More information about the vmkit-commits
mailing list