[vmkit-commits] [vmkit] r180493 - Fixing a bug in secondary class for Class representing arrays. The example which follows used to fail:
Peter Senna Tschudin
peter.senna at gmail.com
Thu Apr 25 10:18:26 PDT 2013
Author: peter.senna
Date: Thu Apr 25 12:16:21 2013
New Revision: 180493
URL: http://llvm.org/viewvc/llvm-project?rev=180493&view=rev
Log:
Fixing a bug in secondary class for Class representing arrays. The example which follows used to fail:
public class Idea2 {
abstract static class A {
int a;
}
static interface IA {
void add();
}
static interface IB extends IA {
void add2();
}
static class B extends A implements IB{
public void add2() {
}
public void add() {
}
}
public static void main(String [] args) {
B[] obj = new B[] {new B(), new B(), new B(), new B()};
IA[] strings = (IA[])obj;
System.out.println(strings);
}
}
(cherry picked from commit c5ed8efbac87b4b281f6d0ae421a3f337c258393)
Modified:
vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp
vmkit/trunk/lib/j3/VMCore/JavaClass.cpp
vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp
Modified: vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp?rev=180493&r1=180492&r2=180493&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/JavaJIT.cpp Thu Apr 25 12:16:21 2013
@@ -1811,7 +1811,7 @@ Value* JavaJIT::getResolvedCommonClass(u
if (alreadyResolved) *alreadyResolved = cl;
node = TheCompiler->getNativeClass(cl);
// Since we only allocate for array classes that we own and
- // ony primitive arrays are already allocated, verify that the class
+ // only primitive arrays are already allocated, verify that the class
// array is not external.
if (TheCompiler->isStaticCompiling() && cl->isArray() &&
node->getType() != intrinsics->JavaClassArrayType) {
Modified: vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp?rev=180493&r1=180492&r2=180493&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/JavaJITOpcodes.cpp Thu Apr 25 12:16:21 2013
@@ -12,6 +12,7 @@
#include <cstring>
+#include <queue>
#include <llvm/Constants.h>
#include <llvm/DerivedTypes.h>
@@ -98,8 +99,9 @@ static inline uint32 WCALC(uint32 n, boo
}
}
-#include <queue>
-
+/**
+ * Used in JavaJIT::findUnreachableCode to find the next instruction in the array of bytecode.
+ */
static uint8 sum [] = {
2,
3,
@@ -112,7 +114,6 @@ static uint8 sum [] = {
2,
2
};
-
static uint8 sum2 [] = {
3,
3,
Modified: vmkit/trunk/lib/j3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaClass.cpp?rev=180493&r1=180492&r2=180493&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JavaClass.cpp Thu Apr 25 12:16:21 2013
@@ -17,7 +17,7 @@
#include "ClasspathReflect.h"
#include "JavaArray.h"
#include "JavaClass.h"
-#include "j3/JavaCompiler.h"
+#include "JavaCompiler.h"
#include "JavaString.h"
#include "JavaConstantPool.h"
#include "JavaObject.h"
@@ -29,8 +29,6 @@
#include "Reader.h"
#include <cstring>
-#include <cstdlib>
-#include <algorithm>
#if 0
using namespace vmkit;
@@ -64,37 +62,9 @@ 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;
@@ -557,9 +527,6 @@ bool JavaVirtualTable::isSubtypeOf(JavaV
return true;
}
}
- if (cl->isArray() && otherVT->cl->isArray()) {
- return baseClassVT->isSubtypeOf(otherVT->baseClassVT);
- }
}
return false;
}
@@ -871,30 +838,6 @@ 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) {
uint32 nbMethods = reader.readU2();
@@ -930,14 +873,13 @@ 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];
+ if (nbMethods < size) {
+ printf("Error in class %s\n", UTF8Buffer(name).cString());
+ }
memcpy(realMethods + size, virtualMethods,
sizeof(JavaMethod) * (nbMethods - size));
@@ -1551,14 +1493,6 @@ 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;
@@ -1662,7 +1596,7 @@ JavaVirtualTable::JavaVirtualTable(Class
// Finally, we must add the list of array of secondary classes from base
nbSecondaryTypes = base->nbInterfaces + superVT->nbSecondaryTypes +
addSuper
-// + base->virtualVT->nbSecondaryTypes
+ + base->virtualVT->nbSecondaryTypes
;
secondaryTypes = (JavaVirtualTable**)
allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes,
@@ -1685,18 +1619,18 @@ JavaVirtualTable::JavaVirtualTable(Class
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;
+ 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
@@ -1792,12 +1726,6 @@ 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;
- }
}
@@ -2181,6 +2109,7 @@ 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);
Modified: vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp?rev=180493&r1=180492&r2=180493&view=diff
==============================================================================
--- vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp (original)
+++ vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp Thu Apr 25 12:16:21 2013
@@ -229,7 +229,7 @@ int Cond::myTimeWait(Lock* l, bool isAbs
absTime.tv_nsec = 0;
}
else {
- absTime.tv_sec = now.tv_sec + secs + 850;
+ absTime.tv_sec = now.tv_sec + secs + 1100; // 150 / 850 / 1000
absTime.tv_nsec = (nsec % NANOSECS_PER_SEC) + now.tv_usec*1000;
if (absTime.tv_nsec >= NANOSECS_PER_SEC) {
absTime.tv_nsec -= NANOSECS_PER_SEC;
More information about the vmkit-commits
mailing list