[vmkit-commits] [vmkit] r197974 - build the interface method descriptor
Gael Thomas
gael.thomas at lip6.fr
Tue Dec 24 02:56:05 PST 2013
Author: gthomas
Date: Tue Dec 24 04:56:04 2013
New Revision: 197974
URL: http://llvm.org/viewvc/llvm-project?rev=197974&view=rev
Log:
build the interface method descriptor
Modified:
vmkit/branches/mcjit/include/j3/j3class.h
vmkit/branches/mcjit/lib/j3/vm/j3class.cc
vmkit/branches/mcjit/lib/j3/vm/j3object.cc
Modified: vmkit/branches/mcjit/include/j3/j3class.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197974&r1=197973&r2=197974&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3class.h (original)
+++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 04:56:04 2013
@@ -7,6 +7,8 @@
#include "vmkit/compiler.h"
+#include "j3/j3object.h"
+
namespace llvm {
class Type;
class GlobalValue;
@@ -27,8 +29,6 @@ namespace j3 {
class J3ArrayClass;
class J3ObjectType;
class J3Method;
- class J3VirtualTable;
- class J3ObjectHandle;
class J3Field;
class J3Type : public vmkit::Symbol {
@@ -147,8 +147,15 @@ namespace j3 {
void dump();
};
+ class J3InterfaceSlotDescriptor {
+ public:
+ uint32_t nbMethods;
+ J3Method** methods;
+ };
+
class J3ObjectType : public J3Type {
- J3ObjectHandle* _javaClass;
+ J3ObjectHandle* _javaClass;
+ J3InterfaceSlotDescriptor _interfaceSlotDescriptors[J3VirtualTable::nbInterfaceMethodTable];
public:
J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name);
@@ -163,6 +170,8 @@ namespace j3 {
J3ObjectHandle* javaClass();
static J3ObjectType* nativeClass(J3ObjectHandle* handle);
+
+ void dumpInterfaceSlotDescriptors();
};
class J3Layout : public J3ObjectType {
Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197974&r1=197973&r2=197974&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 04:56:04 2013
@@ -157,29 +157,65 @@ J3ObjectHandle* J3ObjectType::javaClass(
}
void J3ObjectType::prepareInterfaceTable() {
-#if 0
- for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
- slots[i].nbSlots = 0;
-#endif
+ //fprintf(stderr, "prepare interface table of %ls\n", name()->cStr());
+
+ uint32_t total = 0;
+ J3InterfaceSlotDescriptor* slots = _interfaceSlotDescriptors;
for(uint32_t i=0; i<vt()->checker()->nbSecondaryTypes; i++) {
J3Type* type = vt()->checker()->secondaryTypes[i]->type();
- // fprintf(stderr, " %p %ls type is %p - %p\n", vt(), name()->cStr(), vt()->checker()->secondaryTypes[i], type);
if(type->isClass()) {
J3Class* ifce = vt()->checker()->secondaryTypes[i]->type()->asClass();
- // fprintf(stderr, "processing: %ls from %ls\n", ifce->name()->cStr(), name()->cStr());
if(J3Cst::isInterface(ifce->access())) {
+ //fprintf(stderr, " processing interface: %ls\n", ifce->name()->cStr());
for(uint32_t j=0; j<ifce->nbMethods(); j++) {
J3Method* base = ifce->methods()[j];
- // fprintf(stderr, " %s lookup %ls %ls::%ls in %ls\n",
- // J3Cst::isAbstract(base->access()) ? "abstract" : "concrete",
- // base->sign()->cStr(), base->cl()->name()->cStr(), base->name()->cStr(), name()->cStr());
+ //fprintf(stderr, " processing %s method %ls %ls\n",
+ //J3Cst::isAbstract(base->access()) ? "abstract" : "concrete",
+ //base->sign()->cStr(), base->name()->cStr());
J3Method* method = findVirtualMethod(base->name(), base->sign(), J3Cst::isAbstract(base->access()));
+
+ if(!method)
+ method = base;
+
+ total++;
+ uint32_t index = base->interfaceIndex() % J3VirtualTable::nbInterfaceMethodTable;
+ J3Method** tmp = (J3Method**)alloca(sizeof(J3Method*)*(slots[index].nbMethods+1));
+ memcpy(tmp, slots[index].methods, sizeof(J3Method*)*slots[index].nbMethods);
+ tmp[slots[index].nbMethods] = method;
+ slots[index].methods = tmp;
+ slots[index].nbMethods++;
}
}
}
}
+
+ J3Method** methods = (J3Method**)loader()->allocator()->allocate(total*sizeof(J3Method*));
+ uint32_t cur = 0;
+
+ for(uint32_t i=0; i<J3VirtualTable::nbInterfaceMethodTable; i++) {
+ memcpy(methods + cur, slots[i].methods, slots[i].nbMethods*sizeof(J3Method*));
+ slots[i].methods = methods + cur;
+ cur += slots[i].nbMethods;
+ }
+
+ dumpInterfaceSlotDescriptors();
+}
+
+void J3ObjectType::dumpInterfaceSlotDescriptors() {
+ J3InterfaceSlotDescriptor* slots = _interfaceSlotDescriptors;
+ fprintf(stderr, "slot descriptors of %ls\n", name()->cStr());
+ for(uint32_t i=0; i<J3VirtualTable::nbInterfaceMethodTable; i++) {
+ if(slots[i].nbMethods) {
+ fprintf(stderr, " slot[%d]:\n", i);
+ for(uint32_t j=0; j<slots[i].nbMethods; j++)
+ fprintf(stderr, " %ls::%ls %ls\n",
+ slots[i].methods[j]->cl()->name()->cStr(),
+ slots[i].methods[j]->name()->cStr(),
+ slots[i].methods[j]->sign()->cStr());
+ }
+ }
}
/*
Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197974&r1=197973&r2=197974&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 24 04:56:04 2013
@@ -75,9 +75,11 @@ J3VirtualTable* J3VirtualTable::create(J
if(super != cl) /* super->vt() is not yet allocated for Object */
memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods());
- void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline;
- for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
- res->_interfaceMethodTable[i] = interfaceTrampoline;
+ if(!J3Cst::isAbstract(cl->access())) {
+ void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline;
+ for(uint32_t i=0; i<nbInterfaceMethodTable; i++)
+ res->_interfaceMethodTable[i] = interfaceTrampoline;
+ }
for(uint32_t i=0; i<cl->nbMethods(); i++) {
res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline();
More information about the vmkit-commits
mailing list