[llvm-commits] [vmkit] r52410 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathConstructor.cpp Classpath/ClasspathMethod.cpp VMCore/JavaArray.cpp VMCore/JavaArray.h VMCore/JavaInitialise.cpp VMCore/Jni.cpp VMCore/VirtualTables.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Jun 17 08:40:31 PDT 2008
Author: geoffray
Date: Tue Jun 17 10:40:30 2008
New Revision: 52410
URL: http://llvm.org/viewvc/llvm-project?rev=52410&view=rev
Log:
Simplify array code. JavaObject, JavaArray and ArrayObject do not
have destructors anymore.
Modified:
vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp
vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathConstructor.cpp Tue Jun 17 10:40:30 2008
@@ -54,7 +54,7 @@
jclass Clazz,
jint _meth) {
JavaMethod* meth = (JavaMethod*)_meth;
- ArrayObject* args = (ArrayObject*)_args;
+ JavaArray* args = (JavaArray*)_args;
sint32 nbArgs = args ? args->size : 0;
sint32 size = meth->getSignature()->args.size();
Jnjvm* vm = JavaThread::get()->isolate;
@@ -69,10 +69,10 @@
cl->initialiseClass();
JavaObject* res = cl->doNew(vm);
-
+ JavaObject** ptr = (JavaObject**)(void*)(args->elements);
for (std::vector<Typedef*>::iterator i = meth->getSignature()->args.begin(),
e = meth->getSignature()->args.end(); i != e; ++i, ++index) {
- NativeUtil::decapsulePrimitive(vm, buf, args->at(index), *i);
+ NativeUtil::decapsulePrimitive(vm, buf, ptr[index], *i);
}
JavaObject* excp = 0;
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathMethod.cpp Tue Jun 17 10:40:30 2008
@@ -63,7 +63,7 @@
jobject Meth, jobject _obj, jobject _args, jclass Cl, jint _meth) {
JavaMethod* meth = (JavaMethod*)_meth;
- ArrayObject* args = (ArrayObject*)_args;
+ JavaArray* args = (JavaArray*)_args;
sint32 nbArgs = args ? args->size : 0;
sint32 size = meth->getSignature()->args.size();
Jnjvm* vm = JavaThread::get()->isolate;
@@ -86,10 +86,10 @@
cl->initialiseClass();
}
-
+ JavaObject** ptr = (JavaObject**)(void*)(args->elements);
for (std::vector<Typedef*>::iterator i = meth->getSignature()->args.begin(),
e = meth->getSignature()->args.end(); i != e; ++i, ++index) {
- NativeUtil::decapsulePrimitive(vm, buf, args->at(index), *i);
+ NativeUtil::decapsulePrimitive(vm, buf, ptr[index], *i);
}
JavaObject* exc = 0;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp Tue Jun 17 10:40:30 2008
@@ -46,147 +46,48 @@
extern "C" void outOfMemoryError(sint32 val);
#ifndef MULTIPLE_VM
-#define ACONS(name, elmt, primSize) \
+#define ACONS(name, elmt, primSize, VT) \
name *name::acons(sint32 n, ClassArray* atype, Jnjvm* vm) { \
if (n < 0) \
negativeArraySizeException(n); \
else if (n > JavaArray::MaxArraySize) \
outOfMemoryError(n); \
name* res = (name*) \
- (Object*) operator new(sizeof(name) + n * primSize, name::VT); \
+ (Object*) operator new(sizeof(name) + n * primSize, VT); \
res->initialise(atype); \
res->size = n; \
return res; \
}
#else
-#define ACONS(name, elmt, primSize) \
+#define ACONS(name, elmt, primSize, VT) \
name *name::acons(sint32 n, ClassArray* atype, Jnjvm* vm) { \
if (n < 0) \
negativeArraySizeException(n); \
else if (n > JavaArray::MaxArraySize) \
outOfMemoryError(n); \
name* res = (name*) \
- (Object*) vm->allocateObject(sizeof(name) + n * primSize, name::VT); \
+ (Object*) vm->allocateObject(sizeof(name) + n * primSize, VT); \
res->initialise(atype); \
res->size = n; \
return res; \
}
#endif
-#define AT(name, elmt) \
- elmt name::at(sint32 offset) const { \
- if (offset >= size) \
- JavaThread::get()->isolate->indexOutOfBounds(this, offset); \
- return elements[offset]; \
- } \
- void name::setAt(sint32 offset, elmt value) { \
- if (offset >= size) \
- JavaThread::get()->isolate->indexOutOfBounds(this, offset); \
- elements[offset] = value; \
- }
-
-#define ARRAYCLASS(name, elmt, size) \
- ACONS(name, elmt, size) \
- AT(name, elmt) \
-
-ARRAYCLASS(ArrayUInt8, uint8, 1)
-ARRAYCLASS(ArraySInt8, sint8, 1)
-ARRAYCLASS(ArrayUInt16, uint16, 2)
-ARRAYCLASS(ArraySInt16, sint16, 2)
-ARRAYCLASS(ArrayUInt32, uint32, 4)
-ARRAYCLASS(ArraySInt32, sint32, 4)
-ARRAYCLASS(ArrayLong, sint64, 8)
-ARRAYCLASS(ArrayFloat, float, 4)
-ARRAYCLASS(ArrayDouble, double, 8)
-ARRAYCLASS(ArrayObject, JavaObject*, sizeof(JavaObject*))
+ACONS(ArrayUInt8, uint8, 1, JavaArray::VT)
+ACONS(ArraySInt8, sint8, 1, JavaArray::VT)
+ACONS(ArrayUInt16, uint16, 2, JavaArray::VT)
+ACONS(ArraySInt16, sint16, 2, JavaArray::VT)
+ACONS(ArrayUInt32, uint32, 4, JavaArray::VT)
+ACONS(ArraySInt32, sint32, 4, JavaArray::VT)
+ACONS(ArrayLong, sint64, 8, JavaArray::VT)
+ACONS(ArrayFloat, float, 4, JavaArray::VT)
+ACONS(ArrayDouble, double, 8, JavaArray::VT)
+ACONS(ArrayObject, JavaObject*, sizeof(JavaObject*), ArrayObject::VT)
#undef ARRAYCLASS
#undef ACONS
-#undef AT
-void ArrayUInt8::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeS4(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArraySInt8::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeS4(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArraySInt16::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeS4(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArrayUInt32::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeS4(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArraySInt32::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeS4(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArrayLong::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeS8(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArrayFloat::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeFP(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArrayDouble::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeFP(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-void ArrayObject::print(mvm::PrintBuffer *buf) const {
- buf->write("Array<");
- for (int i = 0; i < size; i++) {
- buf->writeObj(elements[i]);
- buf->write(" ");
- }
- buf->write(">");
-}
-
-
-void ArrayUInt16::print(mvm::PrintBuffer* buf) const {
+void UTF8::print(mvm::PrintBuffer* buf) const {
for (int i = 0; i < size; i++)
buf->writeChar((char)elements[i]);
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Tue Jun 17 10:40:30 2008
@@ -23,10 +23,17 @@
class JavaObject;
class Jnjvm;
-class JavaArray : public JavaObject {
+template <class T>
+class TJavaArray : public JavaObject {
public:
sint32 size;
- void* elements[0];
+ T elements[0];
+};
+
+class JavaArray : public TJavaArray<void*> {
+public:
+ static VirtualTable *VT;
+
static const sint32 MaxArraySize;
static const unsigned int T_BOOLEAN;
static const unsigned int T_CHAR;
@@ -47,20 +54,16 @@
static ClassArray* ofFloat;
static ClassArray* ofDouble;
static ClassArray* ofObject;
+
+ virtual void TRACER;
+
};
-#define ARRAYCLASS(name, elmt) \
-class name : public JavaObject { \
-public: \
- static VirtualTable* VT; \
- sint32 size; \
- elmt elements[0]; \
- static name *acons(sint32 n, ClassArray* cl, Jnjvm* vm); \
- elmt at(sint32) const; \
- void setAt(sint32, elmt); \
- virtual void print(mvm::PrintBuffer* buf) const; \
- virtual void TRACER; \
-}
+#define ARRAYCLASS(name, elmt) \
+ class name : public TJavaArray<elmt> { \
+ public: \
+ static name* acons(sint32 n, ClassArray* cl, Jnjvm* vm); \
+ };
ARRAYCLASS(ArrayUInt8, uint8);
ARRAYCLASS(ArraySInt8, sint8);
@@ -71,10 +74,16 @@
ARRAYCLASS(ArrayLong, sint64);
ARRAYCLASS(ArrayFloat, float);
ARRAYCLASS(ArrayDouble, double);
-ARRAYCLASS(ArrayObject, JavaObject*);
#undef ARRAYCLASS
+class ArrayObject : public TJavaArray<JavaObject*> {
+public:
+ static VirtualTable *VT;
+ static ArrayObject* acons(sint32 n, ClassArray* cl, Jnjvm* vm);
+ virtual void TRACER;
+};
+
class UTF8 : public ArrayUInt16 {
public:
@@ -102,6 +111,8 @@
else return !memcmp(elements, other->elements, size * sizeof(uint16));
}
#endif
+
+ virtual void print(mvm::PrintBuffer* buf) const;
};
} // end namespace jnjvm
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Tue Jun 17 10:40:30 2008
@@ -59,18 +59,11 @@
X fake; \
void* V = ((void**)(void*)(&fake))[0]; \
X::VT = (VirtualTable*)malloc(12 * sizeof(void*) + VT_SIZE); \
+ ((void**)X::VT)[0] = 0; \
memcpy(X::VT, V, VT_SIZE); }
INIT(JavaObject);
- INIT(ArrayUInt8);
- INIT(ArraySInt8);
- INIT(ArrayUInt16);
- INIT(ArraySInt16);
- INIT(ArrayUInt32);
- INIT(ArraySInt32);
- INIT(ArrayLong);
- INIT(ArrayFloat);
- INIT(ArrayDouble);
+ INIT(JavaArray);
INIT(ArrayObject);
#undef INIT
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp Tue Jun 17 10:40:30 2008
@@ -1642,8 +1642,11 @@
jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index) {
BEGIN_EXCEPTION
- return (jobject)((ArrayObject*)array)->at(index);
-
+ ArrayObject* JA = (ArrayObject*)array;
+ if (index >= JA->size)
+ JavaThread::get()->isolate->indexOutOfBounds(JA, index);
+ return (jobject)JA->elements[index];
+
END_EXCEPTION
return 0;
@@ -1655,7 +1658,10 @@
BEGIN_EXCEPTION
- ((ArrayObject*)array)->setAt(index, (JavaObject*)val);
+ ArrayObject* JA = (ArrayObject*)array;
+ if (index >= JA->size)
+ JavaThread::get()->isolate->indexOutOfBounds(JA, index);
+ JA->elements[index] = (JavaObject*)val;
END_EXCEPTION
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=52410&r1=52409&r2=52410&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Tue Jun 17 10:40:30 2008
@@ -12,11 +12,9 @@
#include "JavaArray.h"
#include "JavaCache.h"
#include "JavaClass.h"
-#include "JavaConstantPool.h"
#include "JavaIsolate.h"
#include "JavaObject.h"
#include "JavaThread.h"
-#include "JavaTypes.h"
#include "Jnjvm.h"
#include "LockedMap.h"
#ifdef SERVICE_VM
@@ -27,15 +25,7 @@
#define INIT(X) VirtualTable* X::VT = 0
- INIT(ArrayUInt8);
- INIT(ArraySInt8);
- INIT(ArrayUInt16);
- INIT(ArraySInt16);
- INIT(ArrayUInt32);
- INIT(ArraySInt32);
- INIT(ArrayLong);
- INIT(ArrayFloat);
- INIT(ArrayDouble);
+ INIT(JavaArray);
INIT(ArrayObject);
INIT(CommonClass);
INIT(Class);
@@ -60,23 +50,7 @@
}
}
-#define ARRAYTRACER(name) \
- void name::TRACER { \
- }
-
-
-ARRAYTRACER(ArrayUInt8);
-ARRAYTRACER(ArraySInt8);
-ARRAYTRACER(ArrayUInt16);
-ARRAYTRACER(ArraySInt16);
-ARRAYTRACER(ArrayUInt32);
-ARRAYTRACER(ArraySInt32);
-ARRAYTRACER(ArrayLong);
-ARRAYTRACER(ArrayFloat);
-ARRAYTRACER(ArrayDouble);
-
-#undef ARRAYTRACER
-
+void JavaArray::TRACER {}
#define TRACE_VECTOR(type,alloc,name) { \
for (std::vector<type, alloc<type> >::iterator i = name.begin(), \
More information about the llvm-commits
mailing list