[vmkit-commits] [vmkit] r105410 - in /vmkit/trunk/lib/J3: Compiler/JavaAOTCompiler.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/Jnjvm.cpp VMCore/JnjvmClassLoader.cpp VMCore/Reader.cpp VMCore/VirtualTables.cpp VMCore/Zip.cpp VMCore/Zip.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Jun 3 13:57:35 PDT 2010
Author: geoffray
Date: Thu Jun 3 15:57:35 2010
New Revision: 105410
URL: http://llvm.org/viewvc/llvm-project?rev=105410&view=rev
Log:
Arrays of bytes can only be GC-allocated now.
Modified:
vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
vmkit/trunk/lib/J3/VMCore/JavaClass.h
vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp
vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp
vmkit/trunk/lib/J3/VMCore/Reader.cpp
vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp
vmkit/trunk/lib/J3/VMCore/Zip.cpp
vmkit/trunk/lib/J3/VMCore/Zip.h
Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Thu Jun 3 15:57:35 2010
@@ -1885,8 +1885,7 @@
JavaAOTCompiler* M,
JnjvmBootstrapLoader* bootstrapLoader,
std::vector<Class*>& classes) {
-
- ZipArchive archive(bytes, bootstrapLoader->allocator);
+ ZipArchive archive(&bytes, bootstrapLoader->allocator);
char* realName = (char*)alloca(4096);
for (ZipArchive::table_iterator i = archive.filetable.begin(),
@@ -1898,7 +1897,7 @@
if (size > 6 && !strcmp(&(name[size - 6]), ".class")) {
UserClassArray* array = bootstrapLoader->upcalls->ArrayOfByte;
ArrayUInt8* res =
- (ArrayUInt8*)array->doNew(file->ucsize, bootstrapLoader->allocator);
+ (ArrayUInt8*)array->doNew(file->ucsize, JavaThread::get()->getJVM());
int ok = archive.readFile(res, file);
if (!ok) return;
@@ -1912,7 +1911,7 @@
!strcmp(&name[size - 4], ".zip"))) {
UserClassArray* array = bootstrapLoader->upcalls->ArrayOfByte;
ArrayUInt8* res =
- (ArrayUInt8*)array->doNew(file->ucsize, bootstrapLoader->allocator);
+ (ArrayUInt8*)array->doNew(file->ucsize, JavaThread::get()->getJVM());
int ok = archive.readFile(res, file);
if (!ok) return;
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Thu Jun 3 15:57:35 2010
@@ -254,15 +254,11 @@
}
JavaObject* UserClassArray::doNew(sint32 n, Jnjvm* vm) {
- if (n < 0)
+ if (n < 0) {
vm->negativeArraySizeException(n);
- else if (n > JavaArray::MaxArraySize)
+ } else if (n > JavaArray::MaxArraySize) {
vm->outOfMemoryError();
-
- return doNew(n);
-}
-
-JavaObject* UserClassArray::doNew(sint32 n) {
+ }
JavaObject* res = NULL;
llvm_gcroot(res, 0);
UserCommonClass* cl = baseClass();
@@ -275,29 +271,6 @@
return res;
}
-JavaObject* UserClassArray::doNew(sint32 n, mvm::BumpPtrAllocator& allocator,
- bool temp) {
- UserCommonClass* cl = baseClass();
-
- uint32 logSize = cl->isPrimitive() ?
- cl->asPrimitiveClass()->logSize : (sizeof(JavaObject*) == 8 ? 3 : 2);
- VirtualTable* VT = virtualVT;
- uint32 size = sizeof(JavaObject) + sizeof(ssize_t) + (n << logSize);
-
- JavaObject* res = 0;
-
- // If the array is not temporary, use the allocator.
- if (!temp) {
- res = (JavaObject*)allocator.Allocate(size, "Array");
- } else {
- // Otherwise, allocate with the malloc
- res = (JavaObject*)malloc(size);
- }
- ((void**)res)[0] = VT;
- JavaArray::setSize(res, n);
- return res;
-}
-
void* JavaMethod::compiledPtr() {
if (code != 0) return code;
else {
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Thu Jun 3 15:57:35 2010
@@ -926,12 +926,6 @@
public:
- /// doNew - Allocate a new array with the given allocator.
- ///
- JavaObject* doNew(sint32 n, mvm::BumpPtrAllocator& allocator,
- bool temp = false);
- JavaObject* doNew(sint32 n);
-
/// _baseClass - The base class of the array.
///
CommonClass* _baseClass;
Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Thu Jun 3 15:57:35 2010
@@ -825,7 +825,9 @@
void ClArgumentsInfo::extractClassFromJar(Jnjvm* vm, int argc, char** argv,
int i) {
ArrayUInt8* bytes = NULL;
+ ArrayUInt8* res = NULL;
llvm_gcroot(bytes, 0);
+ llvm_gcroot(res, 0);
jarFile = argv[i];
vm->setClasspath(jarFile);
@@ -837,13 +839,12 @@
return;
}
- ZipArchive archive(bytes, vm->allocator);
+ ZipArchive archive(&bytes, vm->allocator);
if (archive.getOfscd() != -1) {
ZipFile* file = archive.getFile(PATH_MANIFEST);
if (file) {
UserClassArray* array = vm->bootstrapLoader->upcalls->ArrayOfByte;
- ArrayUInt8* res = (ArrayUInt8*)array->doNew(file->ucsize, vm->allocator,
- true);
+ res = (ArrayUInt8*)array->doNew(file->ucsize, vm);
int ok = archive.readFile(res, file);
if (ok) {
char* mainClass = findInformation(vm, res, MAIN_CLASS,
@@ -859,14 +860,12 @@
} else {
printf("Can't extract Manifest file from archive %s\n", jarFile);
}
- free(res);
} else {
printf("Can't find Manifest file in archive %s\n", jarFile);
}
} else {
printf("Can't find archive %s\n", jarFile);
}
- free(bytes);
}
void ClArgumentsInfo::nyi() {
@@ -1255,6 +1254,15 @@
llvm_gcroot(exc, 0);
Jnjvm* vm = thread->getJVM();
+ vm->argumentsInfo.readArgs(vm);
+ if (vm->argumentsInfo.className == NULL) {
+ vm->threadSystem.nonDaemonThreads = 0;
+ return;
+ }
+ int pos = vm->argumentsInfo.appArgumentsPos;
+ vm->argumentsInfo.argv = vm->argumentsInfo.argv + pos - 1;
+ vm->argumentsInfo.argc = vm->argumentsInfo.argc - pos + 1;
+
vm->mainThread = thread;
TRY {
@@ -1323,31 +1331,22 @@
void Jnjvm::runApplication(int argc, char** argv) {
argumentsInfo.argc = argc;
argumentsInfo.argv = argv;
- argumentsInfo.readArgs(this);
- if (argumentsInfo.className) {
- int pos = argumentsInfo.appArgumentsPos;
-
- argumentsInfo.argv = argumentsInfo.argv + pos - 1;
- argumentsInfo.argc = argumentsInfo.argc - pos + 1;
#ifdef SERVICE
- struct sigaction sa;
- sigset_t mask;
- sigfillset(&mask);
- sigaction(SIGUSR1, 0, &sa);
- sa.sa_mask = mask;
- sa.sa_handler = terminationHandler;
- sa.sa_flags |= SA_RESTART;
- sigaction(SIGUSR1, &sa, NULL);
+ struct sigaction sa;
+ sigset_t mask;
+ sigfillset(&mask);
+ sigaction(SIGUSR1, 0, &sa);
+ sa.sa_mask = mask;
+ sa.sa_handler = terminationHandler;
+ sa.sa_flags |= SA_RESTART;
+ sigaction(SIGUSR1, &sa, NULL);
- mvm::Thread* th = new JavaThread(0, 0, this);
- th->start(serviceCPUMonitor);
+ mvm::Thread* th = new JavaThread(0, 0, this);
+ th->start(serviceCPUMonitor);
#endif
- mainThread = new JavaThread(0, 0, this);
- mainThread->start((void (*)(mvm::Thread*))mainJavaStart);
- } else {
- threadSystem.nonDaemonThreads = 0;
- }
+ mainThread = new JavaThread(0, 0, this);
+ mainThread->start((void (*)(mvm::Thread*))mainJavaStart);
}
Jnjvm::Jnjvm(mvm::BumpPtrAllocator& Alloc, JnjvmBootstrapLoader* loader) :
Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Thu Jun 3 15:57:35 2010
@@ -658,9 +658,7 @@
UserClass* JnjvmClassLoader::constructClass(const UTF8* name,
ArrayUInt8* bytes) {
-
- // The array of bytes might be GC-allocated or malloc'd. Consider
- // that this function can never be interrupted.
+ llvm_gcroot(bytes, 0);
assert(bytes && "constructing a class without bytes");
classes->lock.lock();
ClassMap::iterator End = classes->map.end();
@@ -960,11 +958,10 @@
temp[len + 1] = 0;
bootClasspath.push_back(temp);
} else {
- ArrayUInt8* bytes =
- Reader::openFile(this, rp);
+ ArrayUInt8* bytes = Reader::openFile(this, rp);
if (bytes) {
ZipArchive *archive = new(allocator, "ZipArchive")
- ZipArchive(bytes, allocator);
+ ZipArchive(&bytes, allocator);
if (archive) {
bootArchives.push_back(archive);
}
Modified: vmkit/trunk/lib/J3/VMCore/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Reader.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Reader.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/Reader.cpp Thu Jun 3 15:57:35 2010
@@ -35,7 +35,7 @@
long nbb = ftell(fp);
fseek(fp, 0, SeekSet);
UserClassArray* array = loader->upcalls->ArrayOfByte;
- res = (ArrayUInt8*)array->doNew((sint32)nbb, loader->allocator, temp);
+ res = (ArrayUInt8*)array->doNew((sint32)nbb, JavaThread::get()->getJVM());
if (fread(ArrayUInt8::getElements(res), nbb, 1, fp) == 0) {
fprintf(stderr, "fread error\n");
abort();
@@ -52,7 +52,7 @@
ZipFile* file = archive->getFile(filename);
if (file != 0) {
UserClassArray* array = loader->upcalls->ArrayOfByte;
- res = (ArrayUInt8*)array->doNew((sint32)file->ucsize, loader->allocator);
+ res = (ArrayUInt8*)array->doNew((sint32)file->ucsize, JavaThread::get()->getJVM());
if (archive->readFile(res, file) != 0) {
return res;
}
Modified: vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp Thu Jun 3 15:57:35 2010
@@ -29,6 +29,7 @@
#include "Jnjvm.h"
#include "JnjvmClassLoader.h"
#include "LockedMap.h"
+#include "Zip.h"
using namespace j3;
@@ -38,9 +39,9 @@
// absolutely necessary. If there is an easy way to avoid it, do it! Only
// Java classes should be GC classes.
// Having many GC classes gives more work to the GC for the scanning phase
-// and for the relocation phase (for copying collectors.
+// and for the relocation phase (for copying collectors).
//
-// In JnJVM, there is only one internal gc object, the class loader.
+// In J3, there is only one internal gc object, the class loader.
// We decided that this was the best solution because
// otherwise it would involve hacks on the java.lang.Classloader class.
// Therefore, we create a new GC class with a finalize method that will
@@ -99,7 +100,7 @@
}
}
-/// Method for scanning a native array. Only scan the lock. The classloader of
+/// Method for scanning a native array. The classloader of
/// the class is the bootstrap loader and therefore does not need to be
/// scanned here.
extern "C" void JavaArrayTracer(JavaArray* obj, uintptr_t closure) {
@@ -167,9 +168,7 @@
void Class::tracer(uintptr_t closure) {
CommonClass::tracer(closure);
- if (classLoader != classLoader->bootstrapLoader) {
- mvm::Collector::markAndTraceRoot(&bytes, closure);
- }
+ mvm::Collector::markAndTraceRoot(&bytes, closure);
for (uint32 i = 0; i < NR_ISOLATES; ++i) {
TaskClassMirror &M = IsolateInfo[i];
@@ -238,6 +237,11 @@
TRACE_DELEGATEE(upcalls->OfLong);
TRACE_DELEGATEE(upcalls->OfDouble);
#undef TRACE_DELEGATEE
+
+ for (std::vector<ZipArchive*>::iterator i = bootArchives.begin(),
+ e = bootArchives.end(); i != e; i++) {
+ mvm::Collector::markAndTraceRoot((*i)->bytes, closure);
+ }
}
//===----------------------------------------------------------------------===//
Modified: vmkit/trunk/lib/J3/VMCore/Zip.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Zip.cpp?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Zip.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/Zip.cpp Thu Jun 3 15:57:35 2010
@@ -17,7 +17,7 @@
using namespace j3;
-ZipArchive::ZipArchive(ArrayUInt8* bytes, mvm::BumpPtrAllocator& A) : allocator(A) {
+ZipArchive::ZipArchive(ArrayUInt8** bytes, mvm::BumpPtrAllocator& A) : allocator(A) {
this->bytes = bytes;
findOfscd();
if (ofscd > -1) addFiles();
@@ -73,7 +73,7 @@
sint32 minOffs = 0;
sint32 st = END_CENTRAL_DIRECTORY_FILE_HEADER_SIZE + 4;
- Reader reader(&bytes);
+ Reader reader(bytes);
curOffs = reader.max;
if (curOffs >= (65535 + END_CENTRAL_DIRECTORY_FILE_HEADER_SIZE + 4)) {
minOffs = curOffs - (65535 + END_CENTRAL_DIRECTORY_FILE_HEADER_SIZE + 4);
@@ -119,7 +119,7 @@
void ZipArchive::addFiles() {
sint32 temp = ofscd;
- Reader reader(&bytes);
+ Reader reader(bytes);
reader.cursor = temp;
while (true) {
@@ -167,7 +167,7 @@
uint32 extraFieldLength = 0;
uint32 temp = 0;
- Reader reader(&bytes);
+ Reader reader(bytes);
reader.cursor = file->rolh;
if (!(memcmp(ArrayUInt8::getElements(*(reader.bytes)) + file->rolh, HDR_LOCAL, 4))) {
Modified: vmkit/trunk/lib/J3/VMCore/Zip.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Zip.h?rev=105410&r1=105409&r2=105410&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Zip.h (original)
+++ vmkit/trunk/lib/J3/VMCore/Zip.h Thu Jun 3 15:57:35 2010
@@ -49,9 +49,9 @@
public:
std::map<const char*, ZipFile*, ltstr> filetable;
typedef std::map<const char*, ZipFile*, ltstr>::iterator table_iterator;
+ ArrayUInt8** bytes;
private:
- ArrayUInt8* bytes;
void findOfscd();
void addFiles();
@@ -70,7 +70,7 @@
}
int getOfscd() { return ofscd; }
- ZipArchive(ArrayUInt8* bytes, mvm::BumpPtrAllocator& allocator);
+ ZipArchive(ArrayUInt8** bytes, mvm::BumpPtrAllocator& allocator);
ZipFile* getFile(const char* filename);
int readFile(ArrayUInt8* array, const ZipFile* file);
More information about the vmkit-commits
mailing list