[vmkit-commits] [vmkit] r218153 - Play a little with the AOT (does not work yet):

Gael Thomas gael.thomas at lip6.fr
Fri Sep 19 14:32:33 PDT 2014


Author: gthomas
Date: Fri Sep 19 16:32:32 2014
New Revision: 218153

URL: http://llvm.org/viewvc/llvm-project?rev=218153&view=rev
Log:
Play a little with the AOT (does not work yet):
+ Add an AOT option to VmkitGCPrinter (-j3-aot), which avoids trying
  to find a meta data, even if the name starts with JnJVM. I think
  that handling specialized method (or even AOT compiled Java methods)
  is not used since several years, and I don't know if this part of
  the code is usefull. I let it for the moment, but we can know bypass
  it.
+ In case of -j3-aot, for each Java method with gc roots, generate a
  symbol to retrieve the metadata. It should be used to create a Java
  MethodInfo instead of a C MethodInfo when the bytecode is reloaded
  (not implemented).  After having implemented this reloading, we can
  remove the comment behind if(J3AOT) at line 305 (indicates that we
  have a C frame table)
+ Remove the llcj tool (vmjc seems perfect to do aot)
+ Add an example of aot usage in examples/aot

TODO:
+ Avoid multiple definition of static_buf and virtual_buf
  = solution: should probably create a .so from the Java compiled code
  = In this case, have to generate the frametable with the "normal"
    way (see Makefile.rules)
+ Mandatory: start a JVM in the example and load the precompiled code
+ Probably mandatory: manage correctly the reloading of Method Info?



Added:
    vmkit/branches/aot/examples/
    vmkit/branches/aot/examples/aot/   (with props)
    vmkit/branches/aot/examples/aot/HelloWorld.java
    vmkit/branches/aot/examples/aot/Makefile   (with props)
    vmkit/branches/aot/examples/aot/hello.cpp
Removed:
    vmkit/branches/aot/tools/llcj/
Modified:
    vmkit/branches/aot/Makefile.rules
    vmkit/branches/aot/lib/static-gc-printer/VmkitGCPrinter.cpp
    vmkit/branches/aot/tools/Makefile

Modified: vmkit/branches/aot/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/aot/Makefile.rules?rev=218153&r1=218152&r2=218153&view=diff
==============================================================================
--- vmkit/branches/aot/Makefile.rules (original)
+++ vmkit/branches/aot/Makefile.rules Fri Sep 19 16:32:32 2014
@@ -191,7 +191,7 @@ CLANG_FILES=$(patsubst %.c,$(BUILD_DIR)/
             $(patsubst %.cc,$(BUILD_DIR)/%,$(call all-suffixes,.cc)) \
             $(patsubst %.cpp,$(BUILD_DIR)/%,$(call all-suffixes,.cpp))
 
-BC_FILES=$(addsuffix .bc,$(CLANG_FILES)) $(addprefix $(BUILD_DIR)/,$(filter %.bc, $(GEN)))
+BC_FILES+=$(addsuffix .bc,$(CLANG_FILES)) $(addprefix $(BUILD_DIR)/,$(filter %.bc, $(GEN)))
 
 ifdef NEED_BC
 # if we need bytecode, we link a module with all the bc in the build_dir directory, optimize this module
@@ -262,7 +262,7 @@ DEP_LIBS=$(patsubst %,$(LIB_DIR)/lib%.a,
 
 $(BIN_DIR)/$(TOOL)$(EXEEXT): $(MODULE_A) $(DEP_LIBS) $(BUILD_DIR)/frametables.o $(SELF) $(BIN_DIR)/.dir
 	$(Echo) "Linking executable '$(notdir $@)'"
-	$(Verb) $(CLANGXX) -o $@  $(LDFLAGS) $(MODULE_A) $(BUILD_DIR)/frametables.o $(DEP_LIBS) $(DEP_LIBS) $(LIBS)
+	$(Verb) $(CLANGXX) -o $@  $(LDFLAGS) $(BUILD_DIR)/frametables.o $(MODULE_A) $(DEP_LIBS) $(DEP_LIBS) $(LIBS)
 
 $(LIB_DIR)/$(LIBRARY)$(SHLIBEXT): $(MODULE_A) $(DEP_LIBS) $(SELF) $(LIB_DIR)/.dir
 	$(Echo) "Linking shared library '$(notdir $@)'"

Propchange: vmkit/branches/aot/examples/aot/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Sep 19 16:32:32 2014
@@ -0,0 +1 @@
+Release+Asserts

Added: vmkit/branches/aot/examples/aot/HelloWorld.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/aot/examples/aot/HelloWorld.java?rev=218153&view=auto
==============================================================================
--- vmkit/branches/aot/examples/aot/HelloWorld.java (added)
+++ vmkit/branches/aot/examples/aot/HelloWorld.java Fri Sep 19 16:32:32 2014
@@ -0,0 +1,7 @@
+
+
+class HelloWorld {
+	public static void main(String args[]) throws Exception {
+		System.out.println(" ***    bip bip    *****");
+	}
+}

Added: vmkit/branches/aot/examples/aot/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/aot/examples/aot/Makefile?rev=218153&view=auto
==============================================================================
--- vmkit/branches/aot/examples/aot/Makefile (added)
+++ vmkit/branches/aot/examples/aot/Makefile Fri Sep 19 16:32:32 2014
@@ -0,0 +1,28 @@
+##===- tools/j3/Makefile -----------------------------------*- Makefile -*-===##
+# 
+#                     The VMKit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+# 
+##===----------------------------------------------------------------------===##
+LEVEL=../..
+
+BC_FILES=$(BUILD_DIR)/HelloWorld.class.bc
+TOOL=aot-test
+LINK_USE=Classpath J3 J3Compiler Vmkit VmkitCompiler CommonThread FinalMMTk Precompiled
+
+include $(LEVEL)/Makefile.common
+
+%.class.o: %.class.bc
+	$(LLC) -load $(STATIC_GC_PRINTER_LIB) -j3-aot -filetype=obj -o $@ $<
+
+%.class.bc: %.class
+	cd $(BUILD_DIR) && $(VMJC) $(notdir $<)
+
+$(BUILD_DIR)/%.class: %.java $(BUILD_DIR)/.dir
+	$(JAVAC) -d $(BUILD_DIR) $<
+
+check:
+	echo $(MODULE_A_DEP)
+

Propchange: vmkit/branches/aot/examples/aot/Makefile
------------------------------------------------------------------------------
    svn:executable = *

Added: vmkit/branches/aot/examples/aot/hello.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/aot/examples/aot/hello.cpp?rev=218153&view=auto
==============================================================================
--- vmkit/branches/aot/examples/aot/hello.cpp (added)
+++ vmkit/branches/aot/examples/aot/hello.cpp Fri Sep 19 16:32:32 2014
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+	fprintf(stderr, "TODO...\n");
+}

Modified: vmkit/branches/aot/lib/static-gc-printer/VmkitGCPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/aot/lib/static-gc-printer/VmkitGCPrinter.cpp?rev=218153&r1=218152&r2=218153&view=diff
==============================================================================
--- vmkit/branches/aot/lib/static-gc-printer/VmkitGCPrinter.cpp (original)
+++ vmkit/branches/aot/lib/static-gc-printer/VmkitGCPrinter.cpp Fri Sep 19 16:32:32 2014
@@ -32,11 +32,14 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/CommandLine.h"
 #include <cctype>
 #include <cstdio>
 
 using namespace llvm;
 
+cl::opt<bool> J3AOT("j3-aot", cl::desc("Consider that the bitcode was generated by the J3 AOT"));
+
 namespace {
   class VmkitAOTGC : public GCStrategy {
   public:
@@ -208,32 +211,33 @@ static bool methodNameMatches(StringRef
 
 Constant* FindMetadata(const Function& F) {
   LLVMContext& context = F.getParent()->getContext();
-  for (Value::const_use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) {
-    if (const Constant* C = dyn_cast<Constant>(*I)) {
-      if (PointerType* PTy = dyn_cast<PointerType>(C->getType())) {
-        if (isa<IntegerType>(PTy->getContainedType(0))) {
-          // We have found the bitcast constant that casts the method in a i8*
-          for (Value::const_use_iterator CI = C->use_begin(), CE = C->use_end(); CI != CE; ++CI) {
-            if (StructType* STy = dyn_cast<StructType>((*CI)->getType())) {
-              if (STy->getName().equals("JavaMethod")) {
-                const Constant* Method = dyn_cast<Constant>(*CI);
-                const Constant* Array = dyn_cast<Constant>(*((*CI)->use_begin()));
-                Constant* VirtualMethods = dyn_cast<Constant>(const_cast<User*>((*(Array->use_begin()))));
-                uint32_t index = 0;
-                for (; index < Array->getNumOperands(); index++) {
-                  if (Array->getOperand(index) == Method) break;
-                }
-                assert(index != Array->getNumOperands());
-                Constant* GEPs[2] = { ConstantInt::get(Type::getInt32Ty(context), 0),
-                                      ConstantInt::get(Type::getInt32Ty(context), index) };
-                return ConstantExpr::getGetElementPtr(VirtualMethods, GEPs, 2);
-              }
-            }
-          }
-        }
-      }
-    }
-  }
+
+	for (Value::const_use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) {
+		if (const Constant* C = dyn_cast<Constant>(*I)) {
+			if (PointerType* PTy = dyn_cast<PointerType>(C->getType())) {
+				if (isa<IntegerType>(PTy->getContainedType(0))) {
+					// We have found the bitcast constant that casts the method in a i8*
+					for (Value::const_use_iterator CI = C->use_begin(), CE = C->use_end(); CI != CE; ++CI) {
+						if (StructType* STy = dyn_cast<StructType>((*CI)->getType())) {
+							if (STy->getName().equals("JavaMethod")) {
+								const Constant* Method = dyn_cast<Constant>(*CI);
+								const Constant* Array = dyn_cast<Constant>(*((*CI)->use_begin()));
+								Constant* VirtualMethods = dyn_cast<Constant>(const_cast<User*>((*(Array->use_begin()))));
+								uint32_t index = 0;
+								for (; index < Array->getNumOperands(); index++) {
+									if (Array->getOperand(index) == Method) break;
+								}
+								assert(index != Array->getNumOperands());
+								Constant* GEPs[2] = { ConstantInt::get(Type::getInt32Ty(context), 0),
+																			ConstantInt::get(Type::getInt32Ty(context), index) };
+								return ConstantExpr::getGetElementPtr(VirtualMethods, GEPs, 2);
+							}
+						}
+					}
+				}
+			}
+		}
+	}
 
   StringRef name = F.getName();
   if (name.startswith("JnJVM")) {
@@ -265,8 +269,10 @@ Constant* FindMetadata(const Function& F
         return ConstantExpr::getGetElementPtr(VirtualMethods, GEPs, 2);
       }
     }
-    assert(0 && "Should have found a JavaMethod");
+
+		assert(0 && "Should have found a JavaMethod");
   }
+
   return NULL;
 }
 
@@ -290,11 +296,15 @@ Constant* FindMetadata(const Function& F
 ///
 void VmkitAOTGCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
   unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0);
+	uint32_t funcNumber = 0;
 
   AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection());
 
   AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
-  EmitVmkitGlobal(getModule(), AP, "frametable");
+
+	//if(!J3AOT)
+		EmitVmkitGlobal(getModule(), AP, "frametable");
+
   int NumMethodFrames = 0;
   for (iterator I = begin(), IE = end(); I != IE; ++I) {
     NumMethodFrames++;
@@ -305,7 +315,17 @@ void VmkitAOTGCMetadataPrinter::finishAs
   for (iterator I = begin(), IE = end(); I != IE; ++I) {
     GCFunctionInfo &FI = **I;
 
-    Constant* Metadata = FindMetadata(FI.getFunction());
+    Constant* Metadata = J3AOT ? 0 : FindMetadata(FI.getFunction());
+
+    AP.OutStreamer.AddComment("live roots for " +
+                              Twine(FI.getFunction().getName()));
+    AP.OutStreamer.AddBlankLine();
+
+		if(J3AOT) {
+			MCSymbol *FuncId = AP.OutContext.GetOrCreateSymbol("frames_of__" + FI.getFunction().getName());
+			AP.OutStreamer.EmitSymbolAttribute(FuncId, MCSA_Global);
+			AP.OutStreamer.EmitLabel(FuncId);
+		}
 
     int NumDescriptors = 0;
     for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
@@ -327,10 +347,6 @@ void VmkitAOTGCMetadataPrinter::finishAs
                          "(" + Twine(uintptr_t(&FI)) + ")");
     }
 
-    AP.OutStreamer.AddComment("live roots for " +
-                              Twine(FI.getFunction().getName()));
-    AP.OutStreamer.AddBlankLine();
-
     for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
       size_t LiveCount = FI.live_size(J);
       if (LiveCount >= 1<<16) {
@@ -347,11 +363,11 @@ void VmkitAOTGCMetadataPrinter::finishAs
       if (Metadata != NULL) {
         AP.EmitGlobalConstant(Metadata);
       } else {
-        AP.EmitInt32(0);
-        if (IntPtrSize == 8) {
-          AP.EmitInt32(0);
-        }
-      }
+				AP.EmitInt32(0);
+				if (IntPtrSize == 8) {
+					AP.EmitInt32(0);
+				}
+			}
 
       // Return address
       const MCExpr* address = MCSymbolRefExpr::Create(J->Label, AP.OutStreamer.getContext());

Modified: vmkit/branches/aot/tools/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/aot/tools/Makefile?rev=218153&r1=218152&r2=218153&view=diff
==============================================================================
--- vmkit/branches/aot/tools/Makefile (original)
+++ vmkit/branches/aot/tools/Makefile Fri Sep 19 16:32:32 2014
@@ -8,7 +8,7 @@
 ##===----------------------------------------------------------------------===##
 LEVEL = ..
 
-DIRS=j3 vmjc llcj
+DIRS=j3 vmjc
 
 include $(LEVEL)/Makefile.common
 





More information about the vmkit-commits mailing list