[vmkit-commits] [vmkit] r58334 - in /vmkit/trunk: lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/NativeUtil.cpp lib/JnJVM/VMCore/Reader.cpp lib/JnJVM/VMCore/Reader.h lib/JnJVM/VMCore/Zip.h tools/vmjc/Makefile tools/vmjc/vmjc.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Oct 28 10:16:42 PDT 2008


Author: geoffray
Date: Tue Oct 28 12:16:42 2008
New Revision: 58334

URL: http://llvm.org/viewvc/llvm-project?rev=58334&view=rev
Log:
New fixes for static compilation.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Reader.h
    vmkit/trunk/lib/JnJVM/VMCore/Zip.h
    vmkit/trunk/tools/vmjc/Makefile
    vmkit/trunk/tools/vmjc/vmjc.cpp

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Tue Oct 28 12:16:42 2008
@@ -520,7 +520,8 @@
 
 JavaObject* UserClass::doNew(Jnjvm* vm) {
   assert(this && "No class when allocating.");
-  assert(this->isReady() && "Uninitialized class when allocating.");
+  assert((this->isReady() || classLoader->getModule()->isStaticCompiling())
+         && "Uninitialized class when allocating.");
   JavaObject* res = 
     (JavaObject*)vm->gcAllocator.allocateManagedObject(getVirtualSize(),
                                                        getVirtualVT());

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Tue Oct 28 12:16:42 2008
@@ -660,8 +660,10 @@
 ///
 class ClassArray : public CommonClass {
 
-  /// Reader is a friend because it allocates arrays without a vm.
+  /// Reader and Jnjvm are friends because they may allocate arrays without
+  /// a vm.
   friend class Reader;
+  friend class Jnjvm;
 private:
   /// doNew - Allocate a new array with the given allocator.
   ///

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Tue Oct 28 12:16:42 2008
@@ -830,6 +830,22 @@
 }
 
 
+static void compileClass(Class* cl) {
+
+  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+    JavaMethod& meth = cl->virtualMethods[i];
+    if (!isAbstract(meth.access))
+      cl->classLoader->TheModuleProvider->parseFunction(&meth);
+  }
+  
+  for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
+    JavaMethod& meth = cl->staticMethods[i];
+    if (!isAbstract(meth.access))
+      cl->classLoader->TheModuleProvider->parseFunction(&meth);
+  }
+}
+
+
 void Jnjvm::compile(const char* name) {
   bootstrapLoader->analyseClasspathEnv(classpath);
     
@@ -837,21 +853,62 @@
   JavaThread thread(0, this, oldThread->baseSP);
   bootstrapThread = &thread;
   
-
-
-  const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(name);
-  UserClass* cl = bootstrapLoader->loadName(utf8, true, true);
   
-  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-    JavaMethod& meth = cl->virtualMethods[i];
-    bootstrapLoader->TheModuleProvider->parseFunction(&meth);
-  }
+  uint32 size = strlen(name);
+  if (size > 4 && 
+      (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) {
   
-  for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
-    JavaMethod& meth = cl->staticMethods[i];
-    bootstrapLoader->TheModuleProvider->parseFunction(&meth);
-  }
+
+    std::vector<Class*> classes;
+
+    ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name);
+    if (!bytes) unknownError("Can't find zip file.");
+    ZipArchive archive(bytes, bootstrapLoader->allocator);
     
+    char* realName = (char*)alloca(4096);
+    for (ZipArchive::table_iterator i = archive.filetable.begin(), 
+         e = archive.filetable.end(); i != e; ++i) {
+      ZipFile* file = i->second;
+      
+      size = strlen(file->filename);
+      if (size > 6 && !strcmp(&(file->filename[size - 6]), ".class")) {
+        UserClassArray* array = bootstrapLoader->upcalls->ArrayOfByte;
+        ArrayUInt8* res = (ArrayUInt8*)array->doNew(file->ucsize,
+                                                    bootstrapLoader->allocator);
+        int ok = archive.readFile(res, file);
+        if (!ok) unknownError("Wrong zip file.");
+      
+        
+        memcpy(realName, file->filename, size);
+        realName[size - 6] = 0;
+        const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName);
+        Class* cl = bootstrapLoader->constructClass(utf8, res);
+        classes.push_back(cl);
+      }
+    }
+
+    // First resolve everyone so that there can not be unknown references in
+    // constant pools.
+    for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end(); 
+         i != e; ++i) {
+      Class* cl = *i;
+      cl->resolveClass();
+    }
+      
+    for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end(); 
+         i != e; ++i) {
+      Class* cl = *i;
+      if (!cl->isInterface()) compileClass(cl);
+    }
+
+  } else {
+
+    const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(name);
+    UserClass* cl = bootstrapLoader->loadName(utf8, true, true);
+    compileClass(cl);
+  }
+   
+  // Set the linkage to External, so that the printer does not complain.
   llvm::Module* M = bootstrapLoader->getModule();
   for (Module::iterator i = M->begin(), e = M->end(); i != e; ++i) {
     i->setLinkage(llvm::GlobalValue::ExternalLinkage);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp Tue Oct 28 12:16:42 2008
@@ -188,13 +188,6 @@
     if (!res) {
       buf = jniConsFromMeth3(cl, meth, buf);
       res = cl->classLoader->loadLib(buf, jnjvm);
-      if (!res) {
-        printf("Native function %s not found. Probably "
-               "not implemented by JnJVM?\n", meth->printString());
-        JavaJIT::printBacktrace();
-        JavaThread::get()->isolate->unknownError("can not find native method %s",
-                                                 meth->printString());
-      }
     }
   }
   return res;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Reader.cpp Tue Oct 28 12:16:42 2008
@@ -25,7 +25,7 @@
 const int Reader::SeekCur = SEEK_CUR;
 const int Reader::SeekEnd = SEEK_END;
 
-ArrayUInt8* Reader::openFile(JnjvmBootstrapLoader* loader, char* path) {
+ArrayUInt8* Reader::openFile(JnjvmBootstrapLoader* loader, const char* path) {
   FILE* fp = fopen(path, "r");
   ArrayUInt8* res = 0;
   if (fp != 0) {
@@ -41,7 +41,7 @@
 }
 
 ArrayUInt8* Reader::openZip(JnjvmBootstrapLoader* loader, ZipArchive* archive,
-                            char* filename) {
+                            const char* filename) {
   ArrayUInt8* ret = 0;
   ZipFile* file = archive->getFile(filename);
   if (file != 0) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Reader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Reader.h Tue Oct 28 12:16:42 2008
@@ -76,8 +76,8 @@
   static const int SeekCur;
   static const int SeekEnd;
 
-  static ArrayUInt8* openFile(JnjvmBootstrapLoader* loader, char* path);
-  static ArrayUInt8* openZip(JnjvmBootstrapLoader* loader, ZipArchive* archive, char* filename);
+  static ArrayUInt8* openFile(JnjvmBootstrapLoader* loader, const char* path);
+  static ArrayUInt8* openZip(JnjvmBootstrapLoader* loader, ZipArchive* archive, const char* filename);
   
   uint8 readU1() {
     return bytes->elements[cursor++];

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Zip.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Zip.h Tue Oct 28 12:16:42 2008
@@ -34,6 +34,7 @@
 
 class ZipArchive : public mvm::PermanentObject {
   friend class JnjvmBootstrapLoader;
+  friend class Jnjvm;
 private:
   
   mvm::BumpPtrAllocator& allocator;

Modified: vmkit/trunk/tools/vmjc/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/Makefile?rev=58334&r1=58333&r2=58334&view=diff

==============================================================================
--- vmkit/trunk/tools/vmjc/Makefile (original)
+++ vmkit/trunk/tools/vmjc/Makefile Tue Oct 28 12:16:42 2008
@@ -12,7 +12,7 @@
 
 TOOLNAME = vmjc
 USEDLIBS = Allocator CommonThread Mvm JnJVM Classpath $(GCLIB)
-LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitwriter
 
 ifeq ($(ISOLATE_BUILD), 1) 
     USEDLIBS += Isolate

Modified: vmkit/trunk/tools/vmjc/vmjc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=58334&r1=58333&r2=58334&view=diff

==============================================================================
--- vmkit/trunk/tools/vmjc/vmjc.cpp (original)
+++ vmkit/trunk/tools/vmjc/vmjc.cpp Tue Oct 28 12:16:42 2008
@@ -23,6 +23,7 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Streams.h"
+#include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Signals.h"
 
@@ -71,7 +72,8 @@
     mvm::Object::initialise();
     mvm::Thread::initialise();
     Collector::initialise(0, &base);
-  
+    Collector::enable(0);
+
     mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseJVM(true);
     mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(CU);
     vm->compile(InputFilename.c_str());
@@ -97,9 +99,9 @@
         int Len = IFN.length();
         if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
           // Source ends in .bc
-          OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll";
+          OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".bc";
         } else {
-          OutputFilename = IFN+".ll";
+          OutputFilename = IFN+".bc";
         }
 
         if (!Force && std::ifstream(OutputFilename.c_str())) {
@@ -121,14 +123,9 @@
            << ": sending to stdout instead!\n";
       Out = &std::cout;
     }
-
-    // All that llvm-dis does is write the assembly to a file.
-    if (!DontPrint) {
-      PassManager Passes;
-      raw_os_ostream L(*Out);
-      Passes.add(createPrintModulePass(&L));
-      Passes.run(*CU->TheModule);
-    }
+    
+    if (Force || !CheckBitcodeOutputToConsole(Out,true))
+      WriteBitcodeToFile(CU->TheModule, *Out);
 
     if (Out != &std::cout) {
       ((std::ofstream*)Out)->close();





More information about the vmkit-commits mailing list