[llvm-commits] CVS: llvm-java/lib/Compiler/Resolver.h Compiler.cpp Class.h Class.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sun Mar 27 18:46:30 PST 2005
Changes in directory llvm-java/lib/Compiler:
Resolver.h updated: 1.5 -> 1.6
Compiler.cpp updated: 1.259 -> 1.260
Class.h updated: 1.11 -> 1.12
Class.cpp updated: 1.11 -> 1.12
---
Log message:
Resolve and cache field descriptors as well.
---
Diffs of the changes: (+44 -20)
Class.cpp | 21 +++++++++++++++++++--
Class.h | 3 ++-
Compiler.cpp | 38 +++++++++++++++++++++-----------------
Resolver.h | 2 ++
4 files changed, 44 insertions(+), 20 deletions(-)
Index: llvm-java/lib/Compiler/Resolver.h
diff -u llvm-java/lib/Compiler/Resolver.h:1.5 llvm-java/lib/Compiler/Resolver.h:1.6
--- llvm-java/lib/Compiler/Resolver.h:1.5 Sat Mar 26 18:04:10 2005
+++ llvm-java/lib/Compiler/Resolver.h Sun Mar 27 20:46:19 2005
@@ -46,6 +46,8 @@
return classMap_.insert(i, std::make_pair(clazz.getName(), clazz));
}
+ friend class Class;
+
public:
static std::string canonicalizeClassName(const std::string& className) {
if (className[0] == '[')
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.259 llvm-java/lib/Compiler/Compiler.cpp:1.260
--- llvm-java/lib/Compiler/Compiler.cpp:1.259 Sat Mar 26 22:44:51 2005
+++ llvm-java/lib/Compiler/Compiler.cpp Sun Mar 27 20:46:19 2005
@@ -796,10 +796,10 @@
ConstantNameAndType* nameAndType = fieldRef->getNameAndType();
const std::string& className = fieldRef->getClass()->getName()->str();
- GlobalVariable* global =
- getStaticField(class_->getClass(fieldRef->getClassIndex()),
- nameAndType->getName()->str(),
- resolver_->getType(nameAndType->getDescriptor()->str()));
+ GlobalVariable* global = getStaticField(
+ class_->getClassForClass(fieldRef->getClassIndex()),
+ nameAndType->getName()->str(),
+ class_->getClassForDescriptor(nameAndType->getDescriptorIndex()));
assert(global && "Cannot find global for static field!");
@@ -810,12 +810,13 @@
/// super clases, or any of the interfaces it implements.
GlobalVariable* getStaticField(const Class* clazz,
const std::string& name,
- const Type* type) {
+ const Class* fieldClass) {
emitStaticInitializers(clazz->getClassFile());
std::string globalName =
clazz->getClassFile()->getThisClass()->getName()->str() + '/' + name;
DEBUG(std::cerr << "Looking up global: " << globalName << '\n');
+ const Type* type = fieldClass->getType();
if (GlobalVariable* g = module_->getGlobalVariable(globalName, type))
return g;
@@ -851,7 +852,7 @@
class_->getClassFile()->getConstantFieldRef(index);
ConstantNameAndType* nameAndType = fieldRef->getNameAndType();
return getField(
- class_->getClass(fieldRef->getClassIndex()),
+ class_->getClassForClass(fieldRef->getClassIndex()),
nameAndType->getName()->str(),
ptr);
}
@@ -1100,7 +1101,9 @@
for (unsigned i = 0, e = fields.size(); i != e; ++i) {
Field* field = fields[i];
if (field->isStatic()) {
- const Type* globalTy = resolver_->getType(field->getDescriptor()->str());
+ const Class* fieldClass =
+ clazz->getClassForDescriptor(field->getDescriptorIndex());
+ const Type* globalTy = fieldClass->getType();
// A java field can be final/constant even if it has a
// dynamic initializer. Because LLVM does not currently
// support these semantics, we consider constants only
@@ -1633,8 +1636,9 @@
void do_putfield(unsigned index) {
ConstantFieldRef* fieldRef =
class_->getClassFile()->getConstantFieldRef(index);
- const Type* type =
- resolver_->getType(fieldRef->getNameAndType()->getDescriptor()->str());
+ const Class* fieldClass = class_->getClassForDescriptor(
+ fieldRef->getNameAndType()->getDescriptorIndex());
+ const Type* type = fieldClass->getType();
Value* v = pop(type);
Value* p = pop(resolver_->getObjectBaseRefType());
Value* fp = getField(index, p);
@@ -1686,7 +1690,7 @@
const std::string& className = methodRef->getClass()->getName()->str();
- const Class* clazz = class_->getClass(methodRef->getClassIndex());
+ const Class* clazz = class_->getClassForClass(methodRef->getClassIndex());
const VTableInfo* vi = getVTableInfoGeneric(clazz);
const std::string& methodDescr =
@@ -1728,7 +1732,7 @@
const std::string& methodDescr =
methodName + nameAndType->getDescriptor()->str();
std::string funcName = className + '/' + methodDescr;
- const Class* clazz = class_->getClass(methodRef->getClassIndex());
+ const Class* clazz = class_->getClassForClass(methodRef->getClassIndex());
const FunctionType* funcTy = cast<FunctionType>(
resolver_->getType(nameAndType->getDescriptor()->str(), true));
@@ -1740,7 +1744,7 @@
void do_invokestatic(unsigned index) {
ConstantMethodRef* methodRef =
class_->getClassFile()->getConstantMethodRef(index);
- const Class* clazz = class_->getClass(methodRef->getClassIndex());
+ const Class* clazz = class_->getClassForClass(methodRef->getClassIndex());
emitStaticInitializers(clazz->getClassFile());
Method* method = getMethod(methodRef);
Function* function = getFunction(method);
@@ -1767,7 +1771,7 @@
const std::string& className = methodRef->getClass()->getName()->str();
- const Class* clazz = class_->getClass(methodRef->getClassIndex());
+ const Class* clazz = class_->getClassForClass(methodRef->getClassIndex());
const VTableInfo* vi = getVTableInfoGeneric(clazz);
const std::string& methodDescr =
@@ -1840,7 +1844,7 @@
}
void do_new(unsigned index) {
- const Class* clazz = class_->getClass(index);
+ const Class* clazz = class_->getClassForClass(index);
emitStaticInitializers(clazz->getClassFile());
const VTableInfo& vi = getVTableInfo(clazz);
@@ -1929,7 +1933,7 @@
void do_anewarray(unsigned index) {
Value* count = pop(Type::UIntTy);
- const Class* clazz = class_->getClass(index);
+ const Class* clazz = class_->getClassForClass(index);
const Class* arrayClass = resolver_->getArrayClass(clazz);
const VTableInfo* vi = getVTableInfoGeneric(arrayClass);
@@ -1951,7 +1955,7 @@
}
void do_checkcast(unsigned index) {
- const Class* clazz = class_->getClass(index);
+ const Class* clazz = class_->getClassForClass(index);
const VTableInfo* vi = getVTableInfoGeneric(clazz);
Value* objRef = pop(resolver_->getObjectBaseRefType());
@@ -1968,7 +1972,7 @@
}
void do_instanceof(unsigned index) {
- const Class* clazz = class_->getClass(index);
+ const Class* clazz = class_->getClassForClass(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.11 llvm-java/lib/Compiler/Class.h:1.12
--- llvm-java/lib/Compiler/Class.h:1.11 Sat Mar 26 22:20:22 2005
+++ llvm-java/lib/Compiler/Class.h Sun Mar 27 20:46:19 2005
@@ -88,7 +88,8 @@
int getFieldIndex(const std::string& name) const;
llvm::Constant* getConstant(unsigned index) const;
- const Class* getClass(unsigned index) const;
+ const Class* getClassForClass(unsigned index) const;
+ const Class* getClassForDescriptor(unsigned index) const;
};
} } // namespace llvm::Java
Index: llvm-java/lib/Compiler/Class.cpp
diff -u llvm-java/lib/Compiler/Class.cpp:1.11 llvm-java/lib/Compiler/Class.cpp:1.12
--- llvm-java/lib/Compiler/Class.cpp:1.11 Sat Mar 26 22:20:22 2005
+++ llvm-java/lib/Compiler/Class.cpp Sun Mar 27 20:46:19 2005
@@ -121,7 +121,8 @@
// For each of the interfaces we implement, load it and add that
// interface and all the interfaces it inherits from.
for (unsigned i = 0, e = classFile_->getNumInterfaces(); i != e; ++i) {
- const Class* interface = getClass(classFile_->getInterfaceIndex(i));
+ const Class* interface =
+ getClassForClass(classFile_->getInterfaceIndex(i));
interfaces_.push_back(interface);
for (unsigned j = 0, f = interface->getNumInterfaces(); j != f; ++j)
interfaces_.push_back(interface->getInterface(j));
@@ -210,7 +211,7 @@
return static_cast<llvm::Constant*>(resolvedConstantPool_[index]);
}
-const Class* Class::getClass(unsigned index) const
+const Class* Class::getClassForClass(unsigned index) const
{
assert(classFile_ && "No constant pool!");
assert(dynamic_cast<ConstantClass*>(classFile_->getConstant(index)) &&
@@ -225,3 +226,19 @@
return static_cast<const Class*>(resolvedConstantPool_[index]);
}
+
+const Class* Class::getClassForDescriptor(unsigned index) const
+{
+ assert(classFile_ && "No constant pool!");
+ assert(dynamic_cast<ConstantUtf8*>(classFile_->getConstant(index)) &&
+ "Not an index to a descriptor reference!");
+
+ // If we haven't resolved this constant already, do so now.
+ if (!resolvedConstantPool_[index]) {
+ ConstantUtf8* jc = classFile_->getConstantUtf8(index);
+ resolvedConstantPool_[index] =
+ const_cast<Class*>(resolver_->getClassForDesc(jc->str()));
+ }
+
+ return static_cast<const Class*>(resolvedConstantPool_[index]);
+}
More information about the llvm-commits
mailing list