[vmkit-commits] [vmkit] r53138 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaAccess.h JavaArray.cpp JavaArray.h JavaCache.cpp JavaCache.h JavaJIT.cpp JavaRuntimeJIT.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Fri Jul 4 09:22:02 PDT 2008


Author: geoffray
Date: Fri Jul  4 11:22:01 2008
New Revision: 53138

URL: http://llvm.org/viewvc/llvm-project?rev=53138&view=rev
Log:
Simplify & comment.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaAccess.h Fri Jul  4 11:22:01 2008
@@ -6,6 +6,11 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+//
+// This file defines macros and functions for knowing and checking the access
+// type of Java class, fields or methods.
+//
+//===----------------------------------------------------------------------===//
 
 #ifndef JNJVM_JAVA_ACCESS_H
 #define JNJVM_JAVA_ACCESS_H

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp Fri Jul  4 11:22:01 2008
@@ -20,7 +20,10 @@
 
 using namespace jnjvm;
 
+/// This value is the same value than IBM's JVM.
 const sint32 JavaArray::MaxArraySize = 268435455;
+
+/// The JVM defines constants for referencing arrays of primitive types.
 const unsigned int JavaArray::T_BOOLEAN = 4;
 const unsigned int JavaArray::T_CHAR = 5;
 const unsigned int JavaArray::T_FLOAT = 6;
@@ -73,6 +76,7 @@
   }
 #endif
 
+/// Each array class has its own element size for allocating arrays.
 ACONS(ArrayUInt8,  uint8, 1, JavaArray::VT)
 ACONS(ArraySInt8,  sint8, 1, JavaArray::VT)
 ACONS(ArrayUInt16, uint16, 2, JavaArray::VT)
@@ -82,6 +86,10 @@
 ACONS(ArrayLong,   sint64, 8, JavaArray::VT)
 ACONS(ArrayFloat,  float, 4, JavaArray::VT)
 ACONS(ArrayDouble, double, 8, JavaArray::VT)
+
+/// ArrayObject differs wit arrays of primitive types because its
+/// tracer method traces the objects in the array as well as the class of the
+/// array.
 ACONS(ArrayObject, JavaObject*, sizeof(JavaObject*), ArrayObject::VT)
 
 #undef ARRAYCLASS
@@ -150,6 +158,7 @@
   return buf;
 }
 
+/// Currently, this uses malloc/free. This should use a custom memory pool.
 void* UTF8::operator new(size_t sz, sint32 size) {
   return malloc(sz + size * sizeof(uint16));
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Fri Jul  4 11:22:01 2008
@@ -6,6 +6,10 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+//
+// This file defines the internal representation of Java arrays.
+//
+//===----------------------------------------------------------------------===//
 
 #ifndef JNJVM_JAVA_ARRAY_H
 #define JNJVM_JAVA_ARRAY_H
@@ -23,18 +27,38 @@
 class JavaObject;
 class Jnjvm;
 
+/// TJavaArray - Template class to be instantiated by real arrays. All arrays
+///  have a constant size and an array of element. When JnJVM allocates an
+///  instantiation of this class, it allocates with the actual size of this
+///  array. Hence instantiation of TJavaArrays have a layout of 
+///  {JavaObject, size, [0 * T]}.
 template <class T>
 class TJavaArray : public JavaObject {
 public:
+  /// size - The (constant) size of the array.
   sint32 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.
   T elements[1];
 };
 
+/// JavaArray - This class is just a placeholder for constants and for the
+///  virtual table of arrays of primitive types (e.g. double, int).
 class JavaArray : public TJavaArray<void*> {
 public:
-  static VirtualTable *VT;
 
+  /// VT - The virtual table of Java arrays of primitive types (e.g. int,
+  /// double).
+  static VirtualTable *VT;
+  
+  /// MaxArraySize - The maximum size a Java array can have. Allocating an
+  /// array with a bigger size than MaxArraySize raises an out of memory
+  /// error.
   static const sint32 MaxArraySize;
+  
+  /// JVM representation of Java arrays of primitive types.
   static const unsigned int T_BOOLEAN;
   static const unsigned int T_CHAR;
   static const unsigned int T_FLOAT;
@@ -44,6 +68,7 @@
   static const unsigned int T_INT;
   static const unsigned int T_LONG;
 
+  /// The Java class of Java arrays used in JnJVM.
   static ClassArray* ofByte;
   static ClassArray* ofChar;
   static ClassArray* ofString;
@@ -54,11 +79,15 @@
   static ClassArray* ofFloat;
   static ClassArray* ofDouble;
   static ClassArray* ofObject;
-
+  
+  /// tracer - The trace method of Java arrays of primitive types. Since their
+  /// class lives throughout the lifetime of the application, there is no need
+  /// to trace them. Therefore this trace function does nothing.
   virtual void TRACER;
   
 };
 
+/// Instantiation of the TJavaArray class for Java arrays of primitive types.
 #define ARRAYCLASS(name, elmt)                                \
   class name : public TJavaArray<elmt> {                      \
   public:                                                     \
@@ -77,30 +106,63 @@
 
 #undef ARRAYCLASS
 
+/// ArrayObject - Instantiation of the TJavaArray class for arrays of objects.
+/// Arrays of objects are different than arrays of primitive types because
+/// they have to trace all objects in the array.
 class ArrayObject : public TJavaArray<JavaObject*> {
 public:
+  /// VT - The virtual table of arrays of objects.
   static VirtualTable *VT;
+
+  /// acons - Allocates a Java array of objects. The class given as argument is
+  /// the class of the array, not the class of its elements.
   static ArrayObject* acons(sint32 n, ClassArray* cl, Jnjvm* vm);
+
+  /// tracer - The tracer method of Java arrays of objects. This method will
+  /// trace all objects in the array.
   virtual void TRACER;
 };
 
+
+/// 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 : public ArrayUInt16 {
 public:
   
+  /// acons - Allocates an UTF8 in permanent memory. The class argument must be
+  /// JavaArray::ofChar.
   static const UTF8* acons(sint32 n, ClassArray* cl, Jnjvm* vm);
 
+  /// internalToJava - Creates a copy of the UTF8 at its given offset and size
+  /// woth all its '.' replaced by '/'. The JVM bytecode reference classes in
+  /// packages with the '.' as the separating character. The JVM language uses
+  /// the '/' character.
   const UTF8* internalToJava(Jnjvm *vm, unsigned int start,
                              unsigned int len) const;
   
+  /// javaToInternal - Replaces all '/' into '.'.
   const UTF8* javaToInternal(Jnjvm *vm, unsigned int start,
                              unsigned int len) const;
-
+  
+  /// UTF8ToAsciiz - Allocates a C string with the contents of this UTF8.
   char* UTF8ToAsciiz() const;
+
+  /// asciizConstruct - Constructs an UTF8 with the given C string.
   static const UTF8* asciizConstruct(Jnjvm *vm, char* asciiz);
+
+  /// readerConstruct - Constructs an UTF8 with the given buffer and size.
+  /// This function is called when parsing JVM bytecode.
   static const UTF8* readerConstruct(Jnjvm *vm, uint16* buf, uint32 n);
 
+  /// extract - Creates an UTF8 by extracting the contents at the given size
+  /// of this.
   const UTF8* extract(Jnjvm *vm, uint32 start, uint32 len) const;
 
+  /// equals - Returns whether two UTF8s are equals. When the JnJVM executes
+  /// in single mode, equality is just a pointer comparison. When executing
+  /// in multiple mode, we compare the contents f the UTF8s.
 #ifndef MULTIPLE_VM
   bool equals(const UTF8* other) const {
     return this == other;
@@ -112,8 +174,15 @@
   }
 #endif
   
+  /// print - Prints the UTF8 for debugging purposes.
   virtual void print(mvm::PrintBuffer* buf) const;
+
+  /// 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, sint32 size);
+
+  /// operator delete - Redefines the delete operator to remove the object
+  /// from permanent memory.
   void operator delete(void* obj);
 };
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaCache.cpp Fri Jul  4 11:22:01 2008
@@ -37,20 +37,17 @@
   }
 }
 
-void CacheNode::initialise() {
-  this->lastCible = 0;
-  this->methPtr = 0;
-  this->next = 0;
+CacheNode::CacheNode(Enveloppe* E) {
+  lastCible = 0;
+  methPtr = 0;
+  next = 0;
+  enveloppe = E;
 }
 
-Enveloppe* Enveloppe::allocate(JavaCtpInfo* ctp, uint32 index) {
-  Enveloppe* enveloppe = new Enveloppe();
-  enveloppe->firstCache = new CacheNode();
-  enveloppe->firstCache->initialise();
-  enveloppe->firstCache->enveloppe = enveloppe;
-  enveloppe->cacheLock = mvm::Lock::allocNormal();
-  enveloppe->ctpInfo = ctp;
-  enveloppe->index = index;
-  return enveloppe;
+ Enveloppe::Enveloppe(JavaCtpInfo* ctp, uint32 i) {
+  firstCache = new CacheNode(this);
+  cacheLock = mvm::Lock::allocNormal();
+  ctpInfo = ctp;
+  index = i;
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaCache.h Fri Jul  4 11:22:01 2008
@@ -6,6 +6,17 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+//
+// Caches in JnJVM are used when invoking interface methods in the JVM
+// bytecode. A cache is a linked-list of {class, method pointer} pairs that
+// were already encountered during the execution of the program. Its efficiency
+// is based on the hypothesis that for one invokeinterface location, the "this"
+// arguments will share most of the times the same class.
+//
+// At a given time, the first entry in the linked list is the last class of the
+// "this" parameter.
+//
+//===----------------------------------------------------------------------===//
 
 #ifndef JNJVM_JAVA_CACHE_H
 #define JNJVM_JAVA_CACHE_H
@@ -22,28 +33,53 @@
 class Enveloppe;
 class JavaCtpInfo;
 
+/// CacheNode - A {class, method pointer} pair.
 class CacheNode {
 public:
 
+  /// methPtr - The method pointer of this cache.
   void* methPtr;
+
+  /// lastCible - The class of this cache.
   Class* lastCible;
+
+  /// next - The next cache.
   CacheNode* next;
+  
+  /// enveloppe - The container to which this class belongs to.
   Enveloppe* enveloppe;
 
-  void initialise();
-
+  /// CacheNode - Creates a CacheNode with empty values.
+  CacheNode(Enveloppe* E);
 };
 
+/// Enveloppe - A reference to the linked list of CacheNode.
 class Enveloppe {
 public:
   
+  /// ~Enveloppe - Deletes all CacheNode in the linked list.
   ~Enveloppe();
+
+  /// firstCache - The first entry in the linked list, hence the last
+  /// class occurence for a given invokeinterface call.
   CacheNode *firstCache;
+
+  /// ctpInfo - The constant pool info that owns the invokeinterface
+  /// bytecode. This is used to resolve the interface call at its first
+  /// occurence.
   JavaCtpInfo* ctpInfo;
+
+  /// cacheLock - The linked list may be modified by concurrent thread. This
+  /// lock ensures that the list stays consistent.
   mvm::Lock* cacheLock;
+
+  /// index - The index in the constant pool of the interface method.
   uint32 index;
 
-  static Enveloppe* allocate(JavaCtpInfo* info, uint32 index);
+  /// Enveloppe - Allocates the linked list with the given constant pool info
+  /// at the given index, so as the resolution process knows which interface
+  /// method the invokeinterface bytecode references.
+  Enveloppe(JavaCtpInfo* info, uint32 index);
 
 };
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Fri Jul  4 11:22:01 2008
@@ -1979,7 +1979,7 @@
   }
 
   // ok now the cache
-  Enveloppe* enveloppe = Enveloppe::allocate(compilingClass->ctpInfo, index);
+  Enveloppe* enveloppe = new Enveloppe(compilingClass->ctpInfo, index);
   compilingMethod->caches.push_back(enveloppe);
   
   Value* zero = mvm::jit::constantZero;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Fri Jul  4 11:22:01 2008
@@ -65,9 +65,7 @@
   if (!rcache) {
     JavaMethod* dmeth = ocl->lookupMethod(utf8, sign->keyName, false, true);
     if (cache->methPtr) {
-      rcache = new CacheNode();
-      rcache->initialise();
-      rcache->enveloppe = enveloppe;
+      rcache = new CacheNode(enveloppe);
     } else {
       rcache = cache;
     }





More information about the vmkit-commits mailing list