[vmkit-commits] [PATCH] Refactor AOT into ClassLib-specific components, add support for OpenJDK
Nicolas Geoffray
nicolas.geoffray at gmail.com
Fri Nov 4 14:57:19 PDT 2011
Don't you need to fix java.lang.String also?
There is a problem if we don't add the extra fields in LLVM's struct: the
object will be emitted in the executable, and won't be big enough to
contain the two extra fields.
I think we should drop emitting java.lang.Class instances in AOT, because
it does not work with a precise GC. When compiling MMTk (which should be
the only user of AOT without a precise GC), we could be able to just emit
null there. Could you try and confirm?
If it turns out it does not work, we could also try to put a dummy
java.lang.Object or java.lang.Class, following the object layout but
without containing any data. In any case, your change in
vmjcAddPrecompiledClass should be removed.
On Thu, Nov 3, 2011 at 3:37 PM, Will Dietz <wdietz2 at illinois.edu> wrote:
> Inlined below.
>
> Thanks!
>
> ~Will
>
> >From b036d7358b9e57da79e71f04e1869bb9e2015718 Mon Sep 17 00:00:00 2001
> From: Will Dietz <w at wdtz.org>
> Date: Wed, 2 Nov 2011 22:54:23 -0500
> Subject: [PATCH 14/17] Refactor AOT into ClassLib-specific components, add
> support for OpenJDK
>
> * Fix the JavaClass field layout for OpenJDK
> * Restore the Class mapping (stored in an 'extra' field). Ignore PD for
> now,
> since in the Classpath port we emit a null constant for it anyway.
> ---
> lib/J3/Compiler/JavaAOTCompiler.cpp | 36 +++------------
> lib/J3/Compiler/JavaAOTCompilerClasspath.inc | 39 ++++++++++++++++
> lib/J3/Compiler/JavaAOTCompilerOpenJDK.inc | 63
> ++++++++++++++++++++++++++
> lib/J3/VMCore/Precompiled.cpp | 4 ++
> 4 files changed, 112 insertions(+), 30 deletions(-)
> create mode 100644 lib/J3/Compiler/JavaAOTCompilerClasspath.inc
> create mode 100644 lib/J3/Compiler/JavaAOTCompilerOpenJDK.inc
>
> diff --git a/lib/J3/Compiler/JavaAOTCompiler.cpp
> b/lib/J3/Compiler/JavaAOTCompiler.cpp
> index d16d57c..11488df 100644
> --- a/lib/J3/Compiler/JavaAOTCompiler.cpp
> +++ b/lib/J3/Compiler/JavaAOTCompiler.cpp
> @@ -687,36 +687,6 @@ Constant*
> JavaAOTCompiler::CreateConstantForBaseObject(CommonClass* cl) {
> return ConstantStruct::get(STy, Elmts);
> }
>
> -Constant* JavaAOTCompiler::CreateConstantFromJavaClass(CommonClass* cl) {
> - assert(!useCooperativeGC());
> - Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
> - LLVMClassInfo* LCI = getClassInfo(javaClass);
> - StructType* STy =
> - dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
> -
> - std::vector<Constant*> Elmts;
> -
> - // JavaObject
> - Elmts.push_back(CreateConstantForBaseObject(javaClass));
> -
> - // signers
> - Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> -
> - // pd
> - Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> -
> - // vmdata
> - Constant* Cl = getNativeClass(cl);
> - Cl = ConstantExpr::getCast(Instruction::BitCast, Cl,
> - JavaIntrinsics.JavaObjectType);
> - Elmts.push_back(Cl);
> -
> - // constructor
> - Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> -
> - return ConstantStruct::get(STy, Elmts);
> -}
> -
> Constant* JavaAOTCompiler::CreateConstantFromJavaObject(JavaObject* obj) {
> assert(!useCooperativeGC());
> CommonClass* cl = JavaObject::getClass(obj);
> @@ -2557,3 +2527,9 @@ CommonClass*
> JavaAOTCompiler::getUniqueBaseClass(CommonClass* cl) {
> }
> return currentClass;
> }
> +
> +#ifdef USE_OPENJDK
> +#include "JavaAOTCompilerOpenJDK.inc"
> +#else
> +#include "JavaAOTCompilerClasspath.inc"
> +#endif
> diff --git a/lib/J3/Compiler/JavaAOTCompilerClasspath.inc
> b/lib/J3/Compiler/JavaAOTCompilerClasspath.inc
> new file mode 100644
> index 0000000..41199ec
> --- /dev/null
> +++ b/lib/J3/Compiler/JavaAOTCompilerClasspath.inc
> @@ -0,0 +1,39 @@
> +//===----- JavaAOTCompilerClasspath.inc - GNUClasspath AOT support
> --------===//
> +//
> +// The VMKit project
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +Constant* JavaAOTCompiler::CreateConstantFromJavaClass(CommonClass* cl) {
> + assert(!useCooperativeGC());
> + Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
> + LLVMClassInfo* LCI = getClassInfo(javaClass);
> + StructType* STy =
> + dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
> +
> + std::vector<Constant*> Elmts;
> +
> + // JavaObject
> + Elmts.push_back(CreateConstantForBaseObject(javaClass));
> +
> + // signers
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> +
> + // pd
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> +
> + // vmdata
> + Constant* Cl = getNativeClass(cl);
> + Cl = ConstantExpr::getCast(Instruction::BitCast, Cl,
> + JavaIntrinsics.JavaObjectType);
> + Elmts.push_back(Cl);
> +
> + // constructor
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> +
> + return ConstantStruct::get(STy, Elmts);
> +}
> +
> diff --git a/lib/J3/Compiler/JavaAOTCompilerOpenJDK.inc
> b/lib/J3/Compiler/JavaAOTCompilerOpenJDK.inc
> new file mode 100644
> index 0000000..367c56f
> --- /dev/null
> +++ b/lib/J3/Compiler/JavaAOTCompilerOpenJDK.inc
> @@ -0,0 +1,63 @@
> +//===----- JavaAOTCompilerOpenJDK.inc - OpenJDK AOT support
> ---------------===//
> +//
> +// The VMKit project
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +Constant* JavaAOTCompiler::CreateConstantFromJavaClass(CommonClass* cl) {
> + assert(!useCooperativeGC());
> + Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
> + LLVMClassInfo* LCI = getClassInfo(javaClass);
> + StructType* STy =
> + dyn_cast<StructType>(LCI->getVirtualType()->getContainedType(0));
> +
> + std::vector<Constant*> Elmts;
> +
> + // JavaObject
> + Elmts.push_back(CreateConstantForBaseObject(javaClass));
> +
> + // Constructor
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // newInstanceCallerCache
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // Name
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // declaredFields
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // publicFields
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // declaredMethods
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // publicMethods
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // declaredConstructors
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // publicConstructors
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // declaredPublicFields
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // declaredPublicMethods
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // classRedefinedCount
> + Elmts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()),
> 0));
> + // lastRedefinedCount
> + Elmts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()),
> 0));
> + // genericInfo
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // enumConstants
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // enumConstantDictionary
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // annotations
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // declaredAnnotations
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> + // annotationType
> + Elmts.push_back(Constant::getNullValue(JavaIntrinsics.JavaObjectType));
> +
> + return ConstantStruct::get(STy, Elmts);
>
There will be a problem here that java.lang.Class objects will not be
allocated properly. They won't be able to contain the two extra fields,
> +}
> +
> diff --git a/lib/J3/VMCore/Precompiled.cpp b/lib/J3/VMCore/Precompiled.cpp
> index e469eaf..8fdd213 100644
> --- a/lib/J3/VMCore/Precompiled.cpp
> +++ b/lib/J3/VMCore/Precompiled.cpp
> @@ -11,6 +11,7 @@
> #include <dlfcn.h>
> #include "mvm/MethodInfo.h"
>
> +#include "ClasspathReflect.h"
> #include "JavaClass.h"
> #include "JavaUpcalls.h"
> #include "JnjvmClassLoader.h"
> @@ -81,6 +82,9 @@ Class* JnjvmClassLoader::loadClassFromSelf(Jnjvm*
> vm, const char* name) {
> extern "C" void vmjcAddPreCompiledClass(JnjvmClassLoader* JCL,
> CommonClass* cl) {
> cl->classLoader = JCL;
> + // Ensure the Class mapping field is set properly.
> + // (Needed for OpenJDK, since this mapping isn't part of the Class type)
> + JavaObjectClass::setClass((JavaObjectClass*)cl->getDelegatee(),cl);
>
Did you actually run some code that failed because of this not being set?
> }
>
>
> --
> 1.7.5.1
> _______________________________________________
> vmkit-commits mailing list
> vmkit-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/vmkit-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/vmkit-commits/attachments/20111104/25679e94/attachment.html>
More information about the vmkit-commits
mailing list