[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Class.h Class.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sat Mar 26 08:44:51 PST 2005
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.251 -> 1.252
Class.h updated: 1.7 -> 1.8
Class.cpp updated: 1.7 -> 1.8
---
Log message:
Resolve and cache class references as well.
---
Diffs of the changes: (+35 -27)
Class.cpp | 16 ++++++++++++++++
Class.h | 1 +
Compiler.cpp | 45 ++++++++++++++++++---------------------------
3 files changed, 35 insertions(+), 27 deletions(-)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.251 llvm-java/lib/Compiler/Compiler.cpp:1.252
--- llvm-java/lib/Compiler/Compiler.cpp:1.251 Sat Mar 26 09:47:29 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Sat Mar 26 10:44:40 2005
@@ -1039,7 +1039,7 @@
class_->getClassFile()->getConstantFieldRef(index);
ConstantNameAndType* nameAndType = fieldRef->getNameAndType();
return getField(
- &resolver_->getClass(fieldRef->getClass()->getName()->str()),
+ class_->getClass(fieldRef->getClassIndex()),
nameAndType->getName()->str(),
ptr);
}
@@ -1853,7 +1853,7 @@
return params;
}
- const VTableInfo* getVTableInfoGeneric(const Class* clazz) {
+ const VTableInfo* getVTableInfoGeneric(const Class* clazz) {
assert(!clazz->isPrimitive() &&
"Cannot get VTableInfo for primitive class!");
if (clazz->isArray()) {
@@ -1874,7 +1874,7 @@
const std::string& className = methodRef->getClass()->getName()->str();
- const Class* clazz = &resolver_->getClass(className);
+ const Class* clazz = class_->getClass(methodRef->getClassIndex());
const VTableInfo* vi = getVTableInfoGeneric(clazz);
const std::string& methodDescr =
@@ -1916,7 +1916,7 @@
const std::string& methodDescr =
methodName + nameAndType->getDescriptor()->str();
std::string funcName = className + '/' + methodDescr;
- const Class& ci = resolver_->getClass(className);
+ const Class* clazz = class_->getClass(methodRef->getClassIndex());
const FunctionType* funcTy = cast<FunctionType>(
resolver_->getType(nameAndType->getDescriptor()->str(), true));
@@ -1928,8 +1928,8 @@
void do_invokestatic(unsigned index) {
ConstantMethodRef* methodRef =
class_->getClassFile()->getConstantMethodRef(index);
- emitStaticInitializers(
- ClassFile::get(methodRef->getClass()->getName()->str()));
+ const Class* clazz = class_->getClass(methodRef->getClassIndex());
+ emitStaticInitializers(clazz->getClassFile());
Method* method = getMethod(methodRef);
Function* function = getFunction(method);
// Intercept java/lang/System/loadLibrary() calls and add
@@ -1955,7 +1955,7 @@
const std::string& className = methodRef->getClass()->getName()->str();
- const Class* clazz = &resolver_->getClass(className);
+ const Class* clazz = class_->getClass(methodRef->getClassIndex());
const VTableInfo* vi = getVTableInfoGeneric(clazz);
const std::string& methodDescr =
@@ -2028,13 +2028,11 @@
}
void do_new(unsigned index) {
- ConstantClass* classRef =
- class_->getClassFile()->getConstantClass(index);
- const Class& ci = resolver_->getClass(classRef->getName()->str());
- emitStaticInitializers(ci.getClassFile());
- const VTableInfo& vi = getVTableInfo(ci.getClassFile());
+ const Class* clazz = class_->getClass(index);
+ emitStaticInitializers(clazz->getClassFile());
+ const VTableInfo& vi = getVTableInfo(clazz->getClassFile());
- push(allocateObject(ci, vi, currentBB_));
+ push(allocateObject(*clazz, vi, currentBB_));
}
template <typename InsertionPointTy>
@@ -2118,14 +2116,13 @@
void do_anewarray(unsigned index) {
Value* count = pop(Type::UIntTy);
- // FIXME: Need to do handle different element types. This now
- // assumes that all arrays of references are arrays of
+ // FIXME: Need to handle different element types. This now
+ // assumes that all arrays of reference type are arrays of
// java/lang/Object's.
- const Class& clazz = resolver_->getClass("[Ljava/lang/Object;");
- const VTableInfo& vi =
- getObjectArrayVTableInfo(clazz.getComponentClass()->getClassFile());
+ const Class* clazz = &resolver_->getClass("[Ljava/lang/Object;");
+ const VTableInfo* vi = getVTableInfoGeneric(clazz);
- push(allocateArray(clazz, vi, count, currentBB_));
+ push(allocateArray(*clazz, *vi, count, currentBB_));
}
void do_arraylength() {
@@ -2143,10 +2140,7 @@
}
void do_checkcast(unsigned index) {
- ConstantClass* classRef =
- class_->getClassFile()->getConstantClass(index);
-
- const Class* clazz = &resolver_->getClass(classRef->getName()->str());
+ const Class* clazz = class_->getClass(index);
const VTableInfo* vi = getVTableInfoGeneric(clazz);
Value* objRef = pop(resolver_->getObjectBaseRefType());
@@ -2163,10 +2157,7 @@
}
void do_instanceof(unsigned index) {
- ConstantClass* classRef =
- class_->getClassFile()->getConstantClass(index);
-
- const Class* clazz = &resolver_->getClass(classRef->getName()->str());
+ const Class* clazz = class_->getClass(index);
const VTableInfo* vi = getVTableInfoGeneric(clazz);
Value* objRef = pop(resolver_->getObjectBaseRefType());
Index: llvm-java/lib/Compiler/Class.h
diff -u llvm-java/lib/Compiler/Class.h:1.7 llvm-java/lib/Compiler/Class.h:1.8
--- llvm-java/lib/Compiler/Class.h:1.7 Sat Mar 26 08:41:48 2005
+++ llvm-java/lib/Compiler/Class.h Sat Mar 26 10:44:40 2005
@@ -77,6 +77,7 @@
int getFieldIndex(const std::string& name) const;
llvm::Constant* getConstant(unsigned index) const;
+ const Class* getClass(unsigned index) const;
};
} } // namespace llvm::Java
Index: llvm-java/lib/Compiler/Class.cpp
diff -u llvm-java/lib/Compiler/Class.cpp:1.7 llvm-java/lib/Compiler/Class.cpp:1.8
--- llvm-java/lib/Compiler/Class.cpp:1.7 Sat Mar 26 08:41:48 2005
+++ llvm-java/lib/Compiler/Class.cpp Sat Mar 26 10:44:40 2005
@@ -172,3 +172,19 @@
return static_cast<llvm::Constant*>(resolvedConstantPool_[index]);
}
+
+const Class* Class::getClass(unsigned index) const
+{
+ assert(classFile_ && "No constant pool!");
+ assert(dynamic_cast<ConstantClass*>(classFile_->getConstant(index)) &&
+ "Not an index to a class reference!");
+
+ // If we haven't resolved this constant already, do so now.
+ if (!resolvedConstantPool_[index]) {
+ ConstantClass* jc = classFile_->getConstantClass(index);
+ resolvedConstantPool_[index] =
+ const_cast<Class*>(&resolver_->getClass(jc->getName()->str()));
+ }
+
+ return static_cast<const Class*>(resolvedConstantPool_[index]);
+}
More information about the llvm-commits
mailing list