[llvm-commits] CVS: llvm-java/lib/Compiler/VMClass.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Wed Mar 30 23:55:53 PST 2005



Changes in directory llvm-java/lib/Compiler:

VMClass.cpp updated: 1.31 -> 1.32
---
Log message:

Make the layout of a an interface object (it doesn't exist - this is
used only to cast to) the same as java/lang/Object.


---
Diffs of the changes:  (+12 -10)

 VMClass.cpp |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)


Index: llvm-java/lib/Compiler/VMClass.cpp
diff -u llvm-java/lib/Compiler/VMClass.cpp:1.31 llvm-java/lib/Compiler/VMClass.cpp:1.32
--- llvm-java/lib/Compiler/VMClass.cpp:1.31	Thu Mar 31 01:22:43 2005
+++ llvm-java/lib/Compiler/VMClass.cpp	Thu Mar 31 01:55:42 2005
@@ -121,6 +121,15 @@
 
 void VMClass::computeLayout()
 {
+  // If this is an interface, then its layout and type are the same as
+  // java/lang/Object.
+  if (isInterface()) {
+    const VMClass* object = resolver_->getClass("java/lang/Object");
+    layoutType_ = const_cast<Type*>(object->getLayoutType());
+    type_ = object->getType();
+    return;
+  }
+
   std::vector<const Type*> layout;
   if (isArray()) {
     layout.reserve(3);
@@ -128,10 +137,6 @@
     layout.push_back(Type::UIntTy);
     layout.push_back(ArrayType::get(componentClass_->getType(), 0));
   }
-  else if (isInterface()) {
-    layout.reserve(1);
-    layout.push_back(resolver_->getClass("java/lang/Object")->getLayoutType());
-  }
   else {
     if (const VMClass* superClass = getSuperClass())
       layout.push_back(superClass->getLayoutType());
@@ -200,12 +205,9 @@
       for (unsigned i = 0, e = superClass->getNumInterfaces(); i != e; ++i)
         interfaces_.push_back(superClass->getInterface(i));
 
-      // Although we can safely assume that all interfaces inherit
-      // from java/lang/Object, java/lang/Class.getSuperclass()
-      // returns null on interface types. So we only set the
-      // superClass_ field when the class is not an interface type,
-      // but we model the LLVM type of the interface to be as if it
-      // inherits java/lang/Object.
+      // In a classfile an interface is as if it inherits
+      // java/lang/Object, but java/lang/Class/getSuperClass() should
+      // return null on any interface class. Thus we do the same here.
       if (classFile_->isInterface())
         interfaceIndex_ = resolver_->getNextInterfaceIndex();
       else {






More information about the llvm-commits mailing list