[vmkit-commits] [vmkit] r180490 - Removing duplicates in the list of MirandaMethods. It is a good idea for scala programs.
Peter Senna Tschudin
peter.senna at gmail.com
Thu Apr 25 10:17:30 PDT 2013
Author: peter.senna
Date: Thu Apr 25 12:16:00 2013
New Revision: 180490
URL: http://llvm.org/viewvc/llvm-project?rev=180490&view=rev
Log:
Removing duplicates in the list of MirandaMethods. It is a good idea for scala programs.
(cherry picked from commit 512acd5be5440f31e0814ae1d43249c0db503294)
Modified:
vmkit/trunk/lib/j3/VMCore/JavaClass.cpp
Modified: vmkit/trunk/lib/j3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaClass.cpp?rev=180490&r1=180489&r2=180490&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JavaClass.cpp Thu Apr 25 12:16:00 2013
@@ -17,7 +17,7 @@
#include "ClasspathReflect.h"
#include "JavaArray.h"
#include "JavaClass.h"
-#include "JavaCompiler.h"
+#include "j3/JavaCompiler.h"
#include "JavaString.h"
#include "JavaConstantPool.h"
#include "JavaObject.h"
@@ -29,6 +29,8 @@
#include "Reader.h"
#include <cstring>
+#include <cstdlib>
+#include <algorithm>
#if 0
using namespace vmkit;
@@ -62,9 +64,37 @@ extern "C" void ArrayObjectTracer(JavaOb
extern "C" void RegularObjectTracer(JavaObject*);
extern "C" void ReferenceObjectTracer(JavaObject*);
+
+extern "C" bool CheckIfObjectIsAssignableToArrayPosition(JavaObject * obj, JavaObject* array) {
+ llvm_gcroot(obj, 0);
+ llvm_gcroot(array, 0);
+ if (obj == 0)
+ return true;
+ bool b = obj->getVirtualTable()->isSubtypeOf(array->getVirtualTable()->baseClassVT);
+ if (!b) {
+ BEGIN_NATIVE_EXCEPTION(0)
+ Jnjvm* vm = JavaThread::get()->getJVM();
+ vm->CreateArrayStoreException(obj->getVirtualTable());
+ END_NATIVE_EXCEPTION
+ }
+ return b;
+}
+
+extern "C" bool IsSubtypeIntrinsic(JavaVirtualTable* obj, JavaVirtualTable* clazz){
+ //printf("2 + 1 \n");
+ return obj->isSubtypeOf(clazz);
+}
+
+static bool LessThanPtrVirtualTable (JavaVirtualTable * elem1, JavaVirtualTable * elem2) {
+ return elem1 < elem2;
+}
+
+static bool equalsPtrVirtualTable (JavaVirtualTable * elem1, JavaVirtualTable * elem2) {
+ return elem1 == elem2;
+}
+
JavaAttribute::JavaAttribute(const UTF8* name, uint32 length,
uint32 offset) {
-
this->start = offset;
this->nbb = length;
this->name = name;
@@ -355,7 +385,7 @@ JavaMethod* Class::lookupMethodDontThrow
methods = getVirtualMethods();
nb = nbVirtualMethods;
}
-
+
for (uint32 i = 0; i < nb; ++i) {
JavaMethod& res = methods[i];
if (res.name->equals(name) && res.type->equals(type)) {
@@ -527,6 +557,9 @@ bool JavaVirtualTable::isSubtypeOf(JavaV
return true;
}
}
+ if (cl->isArray() && otherVT->cl->isArray()) {
+ return baseClassVT->isSubtypeOf(otherVT->baseClassVT);
+ }
}
return false;
}
@@ -838,8 +871,33 @@ static void computeMirandaMethods(Class*
}
}
+static bool lessThanJavaMethods (JavaMethod* a,JavaMethod* b) {
+ bool flag = a->name->lessThan(b->name);
+ if (!flag) {
+ flag = a->name->equals(b->name);
+ if (flag) {
+ flag = a->type->lessThan(b->type);
+ }
+ }
+ return flag;
+}
+
+static bool cmpJavaMethods (JavaMethod* a,JavaMethod* b) {
+ bool flag = a->name->equals(b->name) && a->type->equals(b->type);
+ return flag;
+}
+
+static void cleanMirandaMethods(std::vector<JavaMethod*>& mirandaMethods) {
+ std::sort(mirandaMethods.begin(), mirandaMethods.end(), lessThanJavaMethods);
+ // using predicate comparison:
+ std::vector<JavaMethod*>::iterator it;
+ it = std::unique (mirandaMethods.begin(), mirandaMethods.end(), cmpJavaMethods); // (no changes)
+ mirandaMethods.resize( std::distance(mirandaMethods.begin(),it) ); // 10 20 30 20 10
+}
+
void Class::readMethods(Reader& reader) {
- uint16 nbMethods = reader.readU2();
+
+ uint32 nbMethods = reader.readU2();
vmkit::ThreadAllocator allocator;
if (isAbstract(access)) {
virtualMethods = (JavaMethod*)
@@ -849,9 +907,10 @@ void Class::readMethods(Reader& reader)
new(classLoader->allocator, "Methods") JavaMethod[nbMethods];
}
staticMethods = virtualMethods + nbMethods;
- for (int i = 0; i < nbMethods; i++) {
+ for (uint32 i = 0; i < nbMethods; i++) {
uint16 access = reader.readU2();
const UTF8* name = ctpInfo->UTF8At(reader.readU2());
+
const UTF8* type = ctpInfo->UTF8At(reader.readU2());
JavaMethod* meth = 0;
if (isStatic(access)) {
@@ -871,11 +930,17 @@ void Class::readMethods(Reader& reader)
std::vector<JavaMethod*> mirandaMethods;
computeMirandaMethods(this, this, mirandaMethods);
uint32 size = mirandaMethods.size();
+ if (size > 100) {
+ cleanMirandaMethods(mirandaMethods);
+ size = mirandaMethods.size();
+ }
nbMethods += size;
JavaMethod* realMethods =
new(classLoader->allocator, "Methods") JavaMethod[nbMethods];
+
memcpy(realMethods + size, virtualMethods,
sizeof(JavaMethod) * (nbMethods - size));
+
nbVirtualMethods += size;
staticMethods = realMethods + nbVirtualMethods;
if (size != 0) {
@@ -1486,6 +1551,14 @@ JavaVirtualTable::JavaVirtualTable(Class
lastIndex += cur->nbSecondaryTypes;
}
+ if (nbSecondaryTypes) {
+ std::sort(secondaryTypes, &secondaryTypes[nbSecondaryTypes],LessThanPtrVirtualTable);
+ JavaVirtualTable** it = std::unique (secondaryTypes, &secondaryTypes[nbSecondaryTypes], equalsPtrVirtualTable); // (no changes)
+ nbSecondaryTypes = std::distance(secondaryTypes,it);
+ //isSortedSecondaryTypes = true;
+ }
+
+
} else {
// Set the tracer, destructor and delete.
tracer = (word_t)JavaObjectTracer;
@@ -1586,8 +1659,11 @@ JavaVirtualTable::JavaVirtualTable(Class
// If the base class implements interfaces, we must also add the
// arrays of these interfaces, of the same dimension than this array
// class and add them to the secondary types list.
+ // Finally, we must add the list of array of secondary classes from base
nbSecondaryTypes = base->nbInterfaces + superVT->nbSecondaryTypes +
- addSuper;
+ addSuper
+// + base->virtualVT->nbSecondaryTypes
+ ;
secondaryTypes = (JavaVirtualTable**)
allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes,
"Secondary types");
@@ -1608,6 +1684,19 @@ JavaVirtualTable::JavaVirtualTable(Class
JavaVirtualTable* CurVT = interface->virtualVT;
secondaryTypes[i + superVT->nbSecondaryTypes + addSuper] = CurVT;
}
+
+// int index = superVT->nbSecondaryTypes + addSuper + base->nbInterfaces;
+// for (uint32 i = 0; i < base->virtualVT->nbSecondaryTypes; ++i) {
+// if (base->virtualVT == base->virtualVT->secondaryTypes[i]) continue;
+//
+// const UTF8* name =
+// JCL->constructArrayName(dim, base->virtualVT->secondaryTypes[i]->cl->name);
+// ClassArray* interface = JCL->constructArray(name);
+// JavaVirtualTable* CurVT = interface->virtualVT;
+// secondaryTypes[index++] = CurVT;
+// }
+//
+// nbSecondaryTypes = index;
} else {
// If the super is not a secondary type and the base class does not
// implement any interface, we can reuse the list of secondary types
@@ -1703,6 +1792,12 @@ JavaVirtualTable::JavaVirtualTable(Class
// java.lang.Object[]. The initialiseVT function will update the current
// array to point to java.lang.Object[]'s secondary list.
}
+ if (offset == getCacheIndex() && nbSecondaryTypes) {
+ std::sort(secondaryTypes, &secondaryTypes[nbSecondaryTypes],LessThanPtrVirtualTable);
+ JavaVirtualTable** it = std::unique (secondaryTypes, &secondaryTypes[nbSecondaryTypes], equalsPtrVirtualTable); // (no changes)
+ nbSecondaryTypes = std::distance(secondaryTypes,it);
+ //isSortedSecondaryTypes = true;
+ }
}
@@ -2086,7 +2181,6 @@ JavaObject* AnnotationReader::createAnno
Jnjvm * vm = JavaThread::get()->getJVM();
Classpath* upcalls = vm->upcalls;
UserClass* HashMap = upcalls->newHashMap;
-
newHashMap = HashMap->doNew(vm);
upcalls->initHashMap->invokeIntSpecial(vm, HashMap, newHashMap);
More information about the vmkit-commits
mailing list