fix openjdk-src build (oversight from type-generator refactor)

This commit is contained in:
Joshua Warner 2014-07-15 08:07:57 -06:00
parent cf835b8cc7
commit bfddef54c6
3 changed files with 310 additions and 258 deletions

View File

@ -2437,7 +2437,7 @@ object findFieldInClass(Thread* t,
GcByteArray* name, GcByteArray* name,
GcByteArray* spec); GcByteArray* spec);
inline object findFieldInClass2(Thread* t, inline GcField* findFieldInClass2(Thread* t,
GcClass* class_, GcClass* class_,
const char* name, const char* name,
const char* spec) const char* spec)
@ -2446,7 +2446,7 @@ inline object findFieldInClass2(Thread* t,
GcByteArray* n = makeByteArray(t, "%s", name); GcByteArray* n = makeByteArray(t, "%s", name);
PROTECT(t, n); PROTECT(t, n);
GcByteArray* s = makeByteArray(t, "%s", spec); GcByteArray* s = makeByteArray(t, "%s", spec);
return findFieldInClass(t, class_, n, s); return cast<GcField>(t, findFieldInClass(t, class_, n, s));
} }
object findMethodInClass(Thread* t, object findMethodInClass(Thread* t,

View File

@ -90,7 +90,7 @@ void listAppend(Thread* t, GcList* list, object value);
GcVector* vectorAppend(Thread* t, GcVector* vector, object value); GcVector* vectorAppend(Thread* t, GcVector* vector, object value);
object growArray(Thread* t, object array); GcArray* growArray(Thread* t, GcArray* array);
object treeQuery(Thread* t, object treeQuery(Thread* t,
GcTreeNode* tree, GcTreeNode* tree,

View File

@ -821,7 +821,7 @@ class MyClasspath : public Classpath {
virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller)
{ {
#ifdef AVIAN_OPENJDK_SRC #ifdef AVIAN_OPENJDK_SRC
return (caller->class_() == type(t, Machine::ClassLoaderType) return (caller->class_() == type(t, GcClassLoader::Type)
and t->libraryLoadStack) and t->libraryLoadStack)
? t->libraryLoadStack->classLoader ? t->libraryLoadStack->classLoader
#else #else
@ -960,7 +960,7 @@ class EmbeddedFile {
#ifdef AVIAN_OPENJDK_SRC #ifdef AVIAN_OPENJDK_SRC
int64_t JNICALL int64_t JNICALL
getFileAttributes(Thread* t, object method, uintptr_t* arguments) getFileAttributes(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
const unsigned Exists = 1; const unsigned Exists = 1;
const unsigned Regular = 2; const unsigned Regular = 2;
@ -969,13 +969,14 @@ int64_t JNICALL
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
object file = reinterpret_cast<object>(arguments[1]); object file = reinterpret_cast<object>(arguments[1]);
object path = fieldAtOffset<object>(file, cp->filePathField); GcString* path
= cast<GcString>(t, fieldAtOffset<object>(file, cp->filePathField));
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, path->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, path, RUNTIME_ARRAY_BODY(p));
replace('\\', '/', RUNTIME_ARRAY_BODY(p)); replace('\\', '/', RUNTIME_ARRAY_BODY(p));
EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), path->length(t));
if (ef.jar) { if (ef.jar) {
if (ef.jarLength == 0) { if (ef.jarLength == 0) {
return Exists | Directory; return Exists | Directory;
@ -1005,18 +1006,21 @@ int64_t JNICALL
return 0; return 0;
} }
} else { } else {
return intValue( return cast<GcInt>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
reinterpret_cast<object>(arguments[0]), reinterpret_cast<object>(arguments[0]),
file)); file))->value();
} }
} }
int64_t JNICALL checkFileAccess(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL
checkFileAccess(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
const unsigned Read = 4; const unsigned Read = 4;
@ -1024,13 +1028,14 @@ int64_t JNICALL checkFileAccess(Thread* t, object method, uintptr_t* arguments)
object file = reinterpret_cast<object>(arguments[1]); object file = reinterpret_cast<object>(arguments[1]);
unsigned mask = arguments[2]; unsigned mask = arguments[2];
object path = fieldAtOffset<object>(file, cp->filePathField); GcString* path
= cast<GcString>(t, fieldAtOffset<object>(file, cp->filePathField));
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, path->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, path, RUNTIME_ARRAY_BODY(p));
replace('\\', '/', RUNTIME_ARRAY_BODY(p)); replace('\\', '/', RUNTIME_ARRAY_BODY(p));
EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), path->length(t));
if (ef.jar) { if (ef.jar) {
if (ef.jarLength == 0) { if (ef.jarLength == 0) {
return mask == Read; return mask == Read;
@ -1058,31 +1063,33 @@ int64_t JNICALL checkFileAccess(Thread* t, object method, uintptr_t* arguments)
return 0; return 0;
} }
} else { } else {
return intValue(t, return cast<GcInt>(t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, t,
methodRuntimeDataNative( cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method))), t, getMethodRuntimeData(t, method)->native())
->original()),
reinterpret_cast<object>(arguments[0]), reinterpret_cast<object>(arguments[0]),
file, file,
mask)) != 0; mask))->value() != 0;
} }
} }
int64_t JNICALL getFileLength(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL getFileLength(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
object file = reinterpret_cast<object>(arguments[1]); object file = reinterpret_cast<object>(arguments[1]);
object path = fieldAtOffset<object>(file, cp->filePathField); GcString* path
= cast<GcString>(t, fieldAtOffset<object>(file, cp->filePathField));
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, path->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, path, RUNTIME_ARRAY_BODY(p));
replace('\\', '/', RUNTIME_ARRAY_BODY(p)); replace('\\', '/', RUNTIME_ARRAY_BODY(p));
EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), path->length(t));
if (ef.jar) { if (ef.jar) {
if (ef.jarLength == 0) { if (ef.jarLength == 0) {
return 0; return 0;
@ -1101,29 +1108,31 @@ int64_t JNICALL getFileLength(Thread* t, object method, uintptr_t* arguments)
return 0; return 0;
} else { } else {
return longValue( return cast<GcLong>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(t,
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), cast<GcNativeIntercept>(
t,
getMethodRuntimeData(t, method)
->native())->original()),
reinterpret_cast<object>(arguments[0]), reinterpret_cast<object>(arguments[0]),
file)); file))->value();
} }
} }
void JNICALL openFile(Thread* t, object method, uintptr_t* arguments) void JNICALL openFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
object path = reinterpret_cast<object>(arguments[1]); GcString* path = cast<GcString>(t, reinterpret_cast<object>(arguments[1]));
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, path->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, path, RUNTIME_ARRAY_BODY(p));
replace('\\', '/', RUNTIME_ARRAY_BODY(p)); replace('\\', '/', RUNTIME_ARRAY_BODY(p));
EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), path->length(t));
if (ef.jar) { if (ef.jar) {
if (ef.jarLength == 0 or ef.pathLength == 0) { if (ef.jarLength == 0 or ef.pathLength == 0) {
throwNew(t, GcFileNotFoundException::Type); throwNew(t, GcFileNotFoundException::Type);
@ -1144,28 +1153,24 @@ void JNICALL openFile(Thread* t, object method, uintptr_t* arguments)
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
int index = -1; int index = -1;
unsigned oldLength = roots(t)->virtualFiles() unsigned oldLength
? arrayLength(t, roots(t)->virtualFiles()) = roots(t)->virtualFiles() ? roots(t)->virtualFiles()->length() : 0;
: 0;
for (unsigned i = 0; i < oldLength; ++i) { for (unsigned i = 0; i < oldLength; ++i) {
if (arrayBody(t, roots(t)->virtualFiles(), i) == 0) { if (roots(t)->virtualFiles()->body()[i] == 0) {
index = i; index = i;
break; break;
} }
} }
if (index == -1) { if (index == -1) {
object newArray = growArray(t, roots(t)->virtualFiles()); GcArray* newArray = growArray(t, roots(t)->virtualFiles());
setRoot(t, Machine::VirtualFiles, newArray); roots(t)->setVirtualFiles(t, newArray);
index = oldLength; index = oldLength;
} }
object region = makeRegion(t, r, 0); object region = makeRegion(t, r, 0);
set(t, roots(t)->virtualFiles()->setBodyElement(t, index, region);
roots(t)->virtualFiles(),
ArrayBody + (index * BytesPerWord),
region);
fieldAtOffset<int32_t>( fieldAtOffset<int32_t>(
fieldAtOffset<object>(this_, cp->fileInputStreamFdField), fieldAtOffset<object>(this_, cp->fileInputStreamFdField),
@ -1173,14 +1178,17 @@ void JNICALL openFile(Thread* t, object method, uintptr_t* arguments)
} else { } else {
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
this_, this_,
path); path);
} }
} }
int64_t JNICALL readByteFromFile(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL
readByteFromFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
@ -1193,14 +1201,14 @@ int64_t JNICALL readByteFromFile(Thread* t, object method, uintptr_t* arguments)
if (fd >= VirtualFileBase) { if (fd >= VirtualFileBase) {
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
object region GcRegion* region = cast<GcRegion>(
= arrayBody(t, roots(t)->virtualFiles(), fd - VirtualFileBase); t, roots(t)->virtualFiles()->body()[fd - VirtualFileBase]);
if (region) { if (region) {
System::Region* r = static_cast<System::Region*>(regionRegion(t, region)); System::Region* r = static_cast<System::Region*>(region->region());
if (r->length() > regionPosition(t, region)) { if (r->length() > region->position()) {
return r->start()[regionPosition(t, region)++]; return r->start()[region->position()++];
} else { } else {
return -1; return -1;
} }
@ -1208,21 +1216,24 @@ int64_t JNICALL readByteFromFile(Thread* t, object method, uintptr_t* arguments)
throwNew(t, GcIoException::Type); throwNew(t, GcIoException::Type);
} }
} else { } else {
return intValue( return cast<GcInt>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
this_)); cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
this_))->value();
} }
} }
int64_t JNICALL int64_t JNICALL
readBytesFromFile(Thread* t, object method, uintptr_t* arguments) readBytesFromFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
object dst = reinterpret_cast<object>(arguments[1]); GcByteArray* dst
= cast<GcByteArray>(t, reinterpret_cast<object>(arguments[1]));
int32_t offset = arguments[2]; int32_t offset = arguments[2];
int32_t length = arguments[3]; int32_t length = arguments[3];
@ -1237,13 +1248,13 @@ int64_t JNICALL
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
object region GcRegion* region = cast<GcRegion>(
= arrayBody(t, roots(t)->virtualFiles(), fd - VirtualFileBase); t, roots(t)->virtualFiles()->body()[fd - VirtualFileBase]);
if (region) { if (region) {
System::Region* r = static_cast<System::Region*>(regionRegion(t, region)); System::Region* r = static_cast<System::Region*>(region->region());
int available = r->length() - regionPosition(t, region); int available = r->length() - region->position();
if (available == 0) { if (available == 0) {
return -1; return -1;
} }
@ -1252,31 +1263,32 @@ int64_t JNICALL
length = available; length = available;
} }
memcpy(&byteArrayBody(t, dst, offset), memcpy(&dst->body()[offset], r->start() + region->position(), length);
r->start() + regionPosition(t, region),
length);
regionPosition(t, region) += length; region->position() += length;
return length; return length;
} else { } else {
throwNew(t, GcIoException::Type); throwNew(t, GcIoException::Type);
} }
} else { } else {
return intValue( return cast<GcInt>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
this_, this_,
dst, dst,
offset, offset,
length)); length))->value();
} }
} }
int64_t JNICALL skipBytesInFile(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL
skipBytesInFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
int64_t count; int64_t count;
@ -1291,37 +1303,39 @@ int64_t JNICALL skipBytesInFile(Thread* t, object method, uintptr_t* arguments)
if (fd >= VirtualFileBase) { if (fd >= VirtualFileBase) {
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
object region GcRegion* region = cast<GcRegion>(
= arrayBody(t, roots(t)->virtualFiles(), fd - VirtualFileBase); t, roots(t)->virtualFiles()->body()[fd - VirtualFileBase]);
if (region) { if (region) {
System::Region* r = static_cast<System::Region*>(regionRegion(t, region)); System::Region* r = static_cast<System::Region*>(region->region());
int available = r->length() - regionPosition(t, region); int available = r->length() - region->position();
if (count > available) { if (count > available) {
count = available; count = available;
} }
regionPosition(t, region) += count; region->position() += count;
return count; return count;
} else { } else {
throwNew(t, GcIoException::Type); throwNew(t, GcIoException::Type);
} }
} else { } else {
return longValue( return cast<GcLong>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(t,
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), cast<GcNativeIntercept>(
t,
getMethodRuntimeData(t, method)
->native())->original()),
this_, this_,
count)); count))->value();
} }
} }
int64_t JNICALL int64_t JNICALL
availableBytesInFile(Thread* t, object method, uintptr_t* arguments) availableBytesInFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
@ -1334,27 +1348,29 @@ int64_t JNICALL
if (fd >= VirtualFileBase) { if (fd >= VirtualFileBase) {
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
object region GcRegion* region = cast<GcRegion>(
= arrayBody(t, roots(t)->virtualFiles(), fd - VirtualFileBase); t, roots(t)->virtualFiles()->body()[fd - VirtualFileBase]);
if (region) { if (region) {
return static_cast<System::Region*>(regionRegion(t, region))->length() return static_cast<System::Region*>(region->region())->length()
- regionPosition(t, region); - region->position();
} else { } else {
throwNew(t, GcIoException::Type); throwNew(t, GcIoException::Type);
} }
} else { } else {
object r = t->m->processor->invoke( object r = t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
this_); this_);
return r ? intValue(t, r) : 0; return r ? cast<GcInt>(t, r)->value() : 0;
} }
} }
void JNICALL closeFile(Thread* t, object method, uintptr_t* arguments) void JNICALL closeFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
@ -1368,18 +1384,21 @@ void JNICALL closeFile(Thread* t, object method, uintptr_t* arguments)
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
int index = fd - VirtualFileBase; int index = fd - VirtualFileBase;
object region = arrayBody(t, roots(t)->virtualFiles(), index); GcRegion* region
= cast<GcRegion>(t, roots(t)->virtualFiles()->body()[index]);
if (region) { if (region) {
static_cast<System::Region*>(regionRegion(t, region))->dispose(); static_cast<System::Region*>(region->region())->dispose();
} }
set(t, roots(t)->virtualFiles(), ArrayBody + (index * BytesPerWord), 0); roots(t)->virtualFiles()->setBodyElement(t, index, 0);
} else { } else {
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
this_); this_);
} }
} }
@ -1431,20 +1450,20 @@ class ZipFile {
Entry entries[0]; Entry entries[0];
}; };
int64_t JNICALL openZipFile(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL openZipFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object path = reinterpret_cast<object>(arguments[0]); GcString* path = cast<GcString>(t, reinterpret_cast<object>(arguments[0]));
int mode = arguments[1]; int mode = arguments[1];
int64_t lastModified; int64_t lastModified;
memcpy(&lastModified, arguments + 2, 8); memcpy(&lastModified, arguments + 2, 8);
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, path->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, path, RUNTIME_ARRAY_BODY(p));
replace('\\', '/', RUNTIME_ARRAY_BODY(p)); replace('\\', '/', RUNTIME_ARRAY_BODY(p));
EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), path->length(t));
if (ef.jar) { if (ef.jar) {
if (ef.jarLength == 0 or ef.pathLength == 0) { if (ef.jarLength == 0 or ef.pathLength == 0) {
throwNew(t, GcFileNotFoundException::Type); throwNew(t, GcFileNotFoundException::Type);
@ -1494,7 +1513,8 @@ int64_t JNICALL openZipFile(Thread* t, object method, uintptr_t* arguments)
while (p < end) { while (p < end) {
if (get4(p) == EntrySignature) { if (get4(p) == EntrySignature) {
unsigned h = hash(fileName(p), fileNameLength(p)); unsigned h
= hash(Slice<const uint8_t>(fileName(p), fileNameLength(p)));
unsigned i = h & (file->indexSize - 1); unsigned i = h & (file->indexSize - 1);
file->index[i] = new (file->entries + (position++)) file->index[i] = new (file->entries + (position++))
@ -1515,23 +1535,24 @@ int64_t JNICALL openZipFile(Thread* t, object method, uintptr_t* arguments)
return reinterpret_cast<int64_t>(file); return reinterpret_cast<int64_t>(file);
} else { } else {
return reinterpret_cast<int64_t>( return reinterpret_cast<int64_t>(
new (t->m->heap->allocate(sizeof(ZipFile))) new (t->m->heap->allocate(sizeof(ZipFile))) ZipFile(
ZipFile(longValue(t, cast<GcLong>(t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(t,
cast<GcNativeIntercept>(
t, t,
methodRuntimeDataNative( getMethodRuntimeData(t, method)
t, getMethodRuntimeData(t, method))), ->native())->original()),
0, 0,
path, path,
mode, mode,
lastModified)))); lastModified))->value()));
} }
} }
int64_t JNICALL int64_t JNICALL
getZipFileEntryCount(Thread* t, object method, uintptr_t* arguments) getZipFileEntryCount(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
@ -1540,14 +1561,16 @@ int64_t JNICALL
if (file->region) { if (file->region) {
return file->entryCount; return file->entryCount;
} else { } else {
return intValue( return cast<GcInt>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
0, 0,
file->file)); file->file))->value();
} }
} }
@ -1563,39 +1586,42 @@ ZipFile::Entry* find(ZipFile* file, const char* path, unsigned pathLength)
return 0; return 0;
} }
int64_t JNICALL getZipFileEntry(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL
getZipFileEntry(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
object path = reinterpret_cast<object>(arguments[2]); GcByteArray* path
= cast<GcByteArray>(t, reinterpret_cast<object>(arguments[2]));
bool addSlash = arguments[3]; bool addSlash = arguments[3];
ZipFile* file = reinterpret_cast<ZipFile*>(peer); ZipFile* file = reinterpret_cast<ZipFile*>(peer);
if (file->region) { if (file->region) {
THREAD_RUNTIME_ARRAY(t, char, p, byteArrayLength(t, path) + 2); THREAD_RUNTIME_ARRAY(t, char, p, path->length() + 2);
memcpy(RUNTIME_ARRAY_BODY(p), memcpy(RUNTIME_ARRAY_BODY(p), path->body().begin(), path->length());
&byteArrayBody(t, path, 0), RUNTIME_ARRAY_BODY(p)[path->length()] = 0;
byteArrayLength(t, path));
RUNTIME_ARRAY_BODY(p)[byteArrayLength(t, path)] = 0;
replace('\\', '/', RUNTIME_ARRAY_BODY(p)); replace('\\', '/', RUNTIME_ARRAY_BODY(p));
if (addSlash) { if (addSlash) {
RUNTIME_ARRAY_BODY(p)[byteArrayLength(t, path)] = '/'; RUNTIME_ARRAY_BODY(p)[path->length()] = '/';
RUNTIME_ARRAY_BODY(p)[byteArrayLength(t, path) + 1] = 0; RUNTIME_ARRAY_BODY(p)[path->length() + 1] = 0;
} }
return reinterpret_cast<int64_t>( return reinterpret_cast<int64_t>(
find(file, RUNTIME_ARRAY_BODY(p), byteArrayLength(t, path))); find(file, RUNTIME_ARRAY_BODY(p), path->length()));
} else { } else {
int64_t entry = longValue( int64_t entry
t, = cast<GcLong>(t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
0, 0,
file->file, file->file,
path, path,
addSlash)); addSlash))->value();
return entry ? reinterpret_cast<int64_t>(new (t->m->heap->allocate( return entry ? reinterpret_cast<int64_t>(new (t->m->heap->allocate(
sizeof(ZipFile::Entry))) ZipFile::Entry(entry)) sizeof(ZipFile::Entry))) ZipFile::Entry(entry))
@ -1604,7 +1630,7 @@ int64_t JNICALL getZipFileEntry(Thread* t, object method, uintptr_t* arguments)
} }
int64_t JNICALL int64_t JNICALL
getZipFileEntryBytes(Thread* t, object method, uintptr_t* arguments) getZipFileEntryBytes(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
@ -1615,9 +1641,9 @@ int64_t JNICALL
switch (type) { switch (type) {
case 0: { // name case 0: { // name
unsigned nameLength = fileNameLength(entry->start); unsigned nameLength = fileNameLength(entry->start);
object array = makeByteArray(t, nameLength + 1); GcByteArray* array = makeByteArray(t, nameLength + 1);
memcpy(&byteArrayBody(t, array, 0), fileName(entry->start), nameLength); memcpy(array->body().begin(), fileName(entry->start), nameLength);
byteArrayBody(t, array, nameLength) = 0; array->body()[nameLength] = 0;
return reinterpret_cast<int64_t>(array); return reinterpret_cast<int64_t>(array);
} break; } break;
@ -1636,8 +1662,10 @@ int64_t JNICALL
} else { } else {
return reinterpret_cast<int64_t>(t->m->processor->invoke( return reinterpret_cast<int64_t>(t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
0, 0,
entry->entry, entry->entry,
type)); type));
@ -1645,7 +1673,7 @@ int64_t JNICALL
} }
int64_t JNICALL int64_t JNICALL
getNextZipFileEntry(Thread* t, object method, uintptr_t* arguments) getNextZipFileEntry(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
@ -1655,15 +1683,18 @@ int64_t JNICALL
if (file->region) { if (file->region) {
return reinterpret_cast<int64_t>(file->entries + index); return reinterpret_cast<int64_t>(file->entries + index);
} else { } else {
int64_t entry = longValue( int64_t entry
t, = cast<GcLong>(t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
0, 0,
file->file, file->file,
index)); index))->value();
return entry ? reinterpret_cast<int64_t>(new (t->m->heap->allocate( return entry ? reinterpret_cast<int64_t>(new (t->m->heap->allocate(
sizeof(ZipFile::Entry))) ZipFile::Entry(entry)) sizeof(ZipFile::Entry))) ZipFile::Entry(entry))
@ -1672,7 +1703,7 @@ int64_t JNICALL
} }
int64_t JNICALL int64_t JNICALL
getZipFileEntryMethod(Thread* t, object method, uintptr_t* arguments) getZipFileEntryMethod(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
@ -1681,19 +1712,21 @@ int64_t JNICALL
if (entry->start) { if (entry->start) {
return compressionMethod(entry->start); return compressionMethod(entry->start);
} else { } else {
return intValue( return cast<GcInt>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
0, 0,
entry->entry)); entry->entry))->value();
} }
} }
int64_t JNICALL getZipFileEntryCompressedSize(Thread* t, int64_t JNICALL getZipFileEntryCompressedSize(Thread* t,
object method, GcMethod* method,
uintptr_t* arguments) uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
@ -1703,19 +1736,21 @@ int64_t JNICALL getZipFileEntryCompressedSize(Thread* t,
if (entry->start) { if (entry->start) {
return compressedSize(entry->start); return compressedSize(entry->start);
} else { } else {
return longValue( return cast<GcLong>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(t,
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), cast<GcNativeIntercept>(
t,
getMethodRuntimeData(t, method)
->native())->original()),
0, 0,
entry->entry)); entry->entry))->value();
} }
} }
int64_t JNICALL getZipFileEntryUncompressedSize(Thread* t, int64_t JNICALL getZipFileEntryUncompressedSize(Thread* t,
object method, GcMethod* method,
uintptr_t* arguments) uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
@ -1725,18 +1760,20 @@ int64_t JNICALL getZipFileEntryUncompressedSize(Thread* t,
if (entry->start) { if (entry->start) {
return uncompressedSize(entry->start); return uncompressedSize(entry->start);
} else { } else {
return longValue( return cast<GcLong>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(t,
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), cast<GcNativeIntercept>(
t,
getMethodRuntimeData(t, method)
->native())->original()),
0, 0,
entry->entry)); entry->entry))->value();
} }
} }
void JNICALL freeZipFileEntry(Thread* t, object method, uintptr_t* arguments) void JNICALL freeZipFileEntry(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t filePeer; int64_t filePeer;
memcpy(&filePeer, arguments, 8); memcpy(&filePeer, arguments, 8);
@ -1748,8 +1785,10 @@ void JNICALL freeZipFileEntry(Thread* t, object method, uintptr_t* arguments)
if (file->region == 0) { if (file->region == 0) {
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
0, 0,
file->file, file->file,
entry->entry); entry->entry);
@ -1758,7 +1797,8 @@ void JNICALL freeZipFileEntry(Thread* t, object method, uintptr_t* arguments)
t->m->heap->free(entry, sizeof(ZipFile::Entry)); t->m->heap->free(entry, sizeof(ZipFile::Entry));
} }
int64_t JNICALL readZipFileEntry(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL
readZipFileEntry(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t filePeer; int64_t filePeer;
memcpy(&filePeer, arguments, 8); memcpy(&filePeer, arguments, 8);
@ -1766,7 +1806,8 @@ int64_t JNICALL readZipFileEntry(Thread* t, object method, uintptr_t* arguments)
memcpy(&entryPeer, arguments + 2, 8); memcpy(&entryPeer, arguments + 2, 8);
int64_t position; int64_t position;
memcpy(&position, arguments + 4, 8); memcpy(&position, arguments + 4, 8);
object buffer = reinterpret_cast<object>(arguments[6]); GcByteArray* buffer
= cast<GcByteArray>(t, reinterpret_cast<object>(arguments[6]));
int offset = arguments[7]; int offset = arguments[7];
int length = arguments[8]; int length = arguments[8];
@ -1782,30 +1823,32 @@ int64_t JNICALL readZipFileEntry(Thread* t, object method, uintptr_t* arguments)
length = size - position; length = size - position;
} }
memcpy(&byteArrayBody(t, buffer, offset), memcpy(&buffer->body()[offset],
fileData(file->region->start() + localHeaderOffset(entry->start)) fileData(file->region->start() + localHeaderOffset(entry->start))
+ position, + position,
length); length);
return length; return length;
} else { } else {
return intValue( return cast<GcInt>(t,
t,
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())
->original()),
0, 0,
file->file, file->file,
entry->entry, entry->entry,
position, position,
buffer, buffer,
offset, offset,
length)); length))->value();
} }
} }
int64_t JNICALL getZipMessage(Thread* t, object method, uintptr_t* arguments) int64_t JNICALL getZipMessage(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
@ -1816,15 +1859,18 @@ int64_t JNICALL getZipMessage(Thread* t, object method, uintptr_t* arguments)
} else { } else {
return reinterpret_cast<int64_t>(t->m->processor->invoke( return reinterpret_cast<int64_t>(t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
0, 0,
file->file)); file->file));
} }
} }
int64_t JNICALL int64_t JNICALL getJarFileMetaInfEntryNames(Thread* t,
getJarFileMetaInfEntryNames(Thread* t, object method, uintptr_t* arguments) GcMethod* method,
uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
@ -1851,13 +1897,15 @@ int64_t JNICALL
return reinterpret_cast<int64_t>(t->m->processor->invoke( return reinterpret_cast<int64_t>(t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
pseudoThis)); pseudoThis));
} }
} }
void JNICALL closeZipFile(Thread* t, object method, uintptr_t* arguments) void JNICALL closeZipFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
int64_t peer; int64_t peer;
memcpy(&peer, arguments, 8); memcpy(&peer, arguments, 8);
@ -1870,8 +1918,10 @@ void JNICALL closeZipFile(Thread* t, object method, uintptr_t* arguments)
} else { } else {
t->m->processor->invoke( t->m->processor->invoke(
t, t,
nativeInterceptOriginal( cast<GcMethod>(
t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), t,
cast<GcNativeIntercept>(
t, getMethodRuntimeData(t, method)->native())->original()),
0, 0,
file->file); file->file);
@ -1923,10 +1973,12 @@ void JNICALL loadLibrary(Thread* t, object, uintptr_t* arguments)
{ {
Thread::LibraryLoadStack stack( Thread::LibraryLoadStack stack(
t, t,
classLoader(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0])))); cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))
->vmClass()
->loader());
object name = reinterpret_cast<object>(arguments[1]); GcString* name = cast<GcString>(t, reinterpret_cast<object>(arguments[1]));
THREAD_RUNTIME_ARRAY(t, char, n, stringLength(t, name) + 1); THREAD_RUNTIME_ARRAY(t, char, n, name->length(t) + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(n)); stringChars(t, name, RUNTIME_ARRAY_BODY(n));
bool absolute = arguments[2]; bool absolute = arguments[2];
@ -1986,45 +2038,45 @@ void interceptFileOperations(Thread* t, bool updateRuntimeData)
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
{ {
object fileClass GcClass* fileClass
= resolveClass(t, roots(t)->bootLoader(), "java/io/File", false); = resolveClass(t, roots(t)->bootLoader(), "java/io/File", false);
if (fileClass) { if (fileClass) {
object filePathField GcField* filePathField
= findFieldInClass2(t, fileClass, "path", "Ljava/lang/String;"); = findFieldInClass2(t, fileClass, "path", "Ljava/lang/String;");
if (filePathField) { if (filePathField) {
cp->filePathField = fieldOffset(t, filePathField); cp->filePathField = filePathField->offset();
} }
} }
} }
{ {
object fileDescriptorClass = resolveClass( GcClass* fileDescriptorClass = resolveClass(
t, roots(t)->bootLoader(), "java/io/FileDescriptor", false); t, roots(t)->bootLoader(), "java/io/FileDescriptor", false);
if (fileDescriptorClass) { if (fileDescriptorClass) {
object fileDescriptorFdField GcField* fileDescriptorFdField
= findFieldInClass2(t, fileDescriptorClass, "fd", "I"); = findFieldInClass2(t, fileDescriptorClass, "fd", "I");
if (fileDescriptorFdField) { if (fileDescriptorFdField) {
cp->fileDescriptorFdField = fieldOffset(t, fileDescriptorFdField); cp->fileDescriptorFdField = fileDescriptorFdField->offset();
} }
} }
} }
{ {
object fileInputStreamClass = resolveClass( GcClass* fileInputStreamClass = resolveClass(
t, roots(t)->bootLoader(), "java/io/FileInputStream", false); t, roots(t)->bootLoader(), "java/io/FileInputStream", false);
if (fileInputStreamClass) { if (fileInputStreamClass) {
PROTECT(t, fileInputStreamClass); PROTECT(t, fileInputStreamClass);
object fileInputStreamFdField = findFieldInClass2( GcField* fileInputStreamFdField = findFieldInClass2(
t, fileInputStreamClass, "fd", "Ljava/io/FileDescriptor;"); t, fileInputStreamClass, "fd", "Ljava/io/FileDescriptor;");
if (fileInputStreamFdField) { if (fileInputStreamFdField) {
cp->fileInputStreamFdField = fieldOffset(t, fileInputStreamFdField); cp->fileInputStreamFdField = fileInputStreamFdField->offset();
intercept(t, intercept(t,
fileInputStreamClass, fileInputStreamClass,
@ -2081,17 +2133,17 @@ void interceptFileOperations(Thread* t, bool updateRuntimeData)
} }
{ {
object zipFileClass = resolveClass( GcClass* zipFileClass = resolveClass(
t, roots(t)->bootLoader(), "java/util/zip/ZipFile", false); t, roots(t)->bootLoader(), "java/util/zip/ZipFile", false);
if (zipFileClass) { if (zipFileClass) {
PROTECT(t, zipFileClass); PROTECT(t, zipFileClass);
object zipFileJzfileField GcField* zipFileJzfileField
= findFieldInClass2(t, zipFileClass, "jzfile", "J"); = findFieldInClass2(t, zipFileClass, "jzfile", "J");
if (zipFileJzfileField) { if (zipFileJzfileField) {
cp->zipFileJzfileField = fieldOffset(t, zipFileJzfileField); cp->zipFileJzfileField = zipFileJzfileField->offset();
intercept(t, intercept(t,
zipFileClass, zipFileClass,
@ -2181,7 +2233,7 @@ void interceptFileOperations(Thread* t, bool updateRuntimeData)
} }
{ {
object jarFileClass = resolveClass( GcClass* jarFileClass = resolveClass(
t, roots(t)->bootLoader(), "java/util/jar/JarFile", false); t, roots(t)->bootLoader(), "java/util/jar/JarFile", false);
if (jarFileClass) { if (jarFileClass) {
@ -2203,7 +2255,7 @@ void interceptFileOperations(Thread* t, bool updateRuntimeData)
const char* const gbaMethodName = "getBooleanAttributes0"; const char* const gbaMethodName = "getBooleanAttributes0";
#endif #endif
object fsClass GcClass* fsClass
= resolveClass(t, roots(t)->bootLoader(), fsClassName, false); = resolveClass(t, roots(t)->bootLoader(), fsClassName, false);
if (fsClass) { if (fsClass) {
@ -2895,7 +2947,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(Thread* t, Avian_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(Thread* t,
object method, GcMethod* method,
uintptr_t* arguments) uintptr_t* arguments)
{ {
return Avian_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J( return Avian_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(