2012-05-11 23:43:27 +00:00
|
|
|
/* Copyright (c) 2008-2012, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-07-06 23:50:26 +00:00
|
|
|
#include "machine.h"
|
2007-07-24 01:44:20 +00:00
|
|
|
#include "constants.h"
|
2007-09-24 01:39:03 +00:00
|
|
|
#include "processor.h"
|
2009-08-10 13:56:16 +00:00
|
|
|
#include "util.h"
|
2007-07-06 15:24:06 +00:00
|
|
|
|
2007-07-24 01:44:20 +00:00
|
|
|
using namespace vm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
int64_t
|
2010-09-14 16:49:41 +00:00
|
|
|
search(Thread* t, object loader, object name,
|
|
|
|
object (*op)(Thread*, object, object), bool replaceDots)
|
2007-07-07 23:47:35 +00:00
|
|
|
{
|
2007-09-18 23:30:09 +00:00
|
|
|
if (LIKELY(name)) {
|
2010-09-14 16:49:41 +00:00
|
|
|
PROTECT(t, loader);
|
2009-06-11 23:13:25 +00:00
|
|
|
PROTECT(t, name);
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
object n = makeByteArray(t, stringLength(t, name) + 1);
|
2007-09-18 23:30:09 +00:00
|
|
|
char* s = reinterpret_cast<char*>(&byteArrayBody(t, n, 0));
|
2009-05-26 02:02:25 +00:00
|
|
|
stringChars(t, name, s);
|
2007-09-18 23:30:09 +00:00
|
|
|
|
|
|
|
if (replaceDots) {
|
|
|
|
replace('.', '/', s);
|
|
|
|
}
|
|
|
|
|
2010-12-27 22:55:23 +00:00
|
|
|
return reinterpret_cast<int64_t>(op(t, loader, n));
|
2007-09-18 23:30:09 +00:00
|
|
|
} else {
|
2010-12-27 22:55:23 +00:00
|
|
|
throwNew(t, Machine::NullPointerExceptionType);
|
2007-09-18 23:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 16:49:41 +00:00
|
|
|
object
|
|
|
|
resolveSystemClassThrow(Thread* t, object loader, object spec)
|
2010-09-01 16:13:52 +00:00
|
|
|
{
|
2011-03-18 03:42:15 +00:00
|
|
|
return resolveSystemClass
|
|
|
|
(t, loader, spec, true, Machine::ClassNotFoundExceptionType);
|
2010-09-01 16:13:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 16:49:41 +00:00
|
|
|
} // namespace
|
2007-08-10 23:45:47 +00:00
|
|
|
|
2011-03-27 05:24:48 +00:00
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_avian_Classes_acquireClassLock
|
|
|
|
(Thread* t, object, uintptr_t*)
|
|
|
|
{
|
|
|
|
acquire(t, t->m->classLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_avian_Classes_releaseClassLock
|
|
|
|
(Thread* t, object, uintptr_t*)
|
|
|
|
{
|
|
|
|
release(t, t->m->classLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_avian_Classes_resolveVMClass
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object loader = reinterpret_cast<object>(arguments[0]);
|
|
|
|
object spec = reinterpret_cast<object>(arguments[1]);
|
|
|
|
|
|
|
|
return reinterpret_cast<int64_t>
|
|
|
|
(resolveClass(t, loader, spec, true, Machine::ClassNotFoundExceptionType));
|
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2010-09-01 16:13:52 +00:00
|
|
|
Avian_avian_SystemClassLoader_findLoadedVMClass
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2007-07-24 01:44:20 +00:00
|
|
|
{
|
2010-09-14 16:49:41 +00:00
|
|
|
object loader = reinterpret_cast<object>(arguments[0]);
|
|
|
|
object name = reinterpret_cast<object>(arguments[1]);
|
2007-07-24 01:44:20 +00:00
|
|
|
|
2010-09-14 16:49:41 +00:00
|
|
|
return search(t, loader, name, findLoadedClass, true);
|
2007-07-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2010-09-01 16:13:52 +00:00
|
|
|
Avian_avian_SystemClassLoader_findVMClass
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2009-12-25 00:58:48 +00:00
|
|
|
{
|
|
|
|
object loader = reinterpret_cast<object>(arguments[0]);
|
2010-09-14 16:49:41 +00:00
|
|
|
object name = reinterpret_cast<object>(arguments[1]);
|
2009-12-25 00:58:48 +00:00
|
|
|
|
2010-09-14 16:49:41 +00:00
|
|
|
return search(t, loader, name, resolveSystemClassThrow, true);
|
2009-12-25 00:58:48 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2011-03-26 01:14:21 +00:00
|
|
|
Avian_avian_SystemClassLoader_resourceURLPrefix
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2007-07-30 23:19:05 +00:00
|
|
|
{
|
2010-09-14 16:49:41 +00:00
|
|
|
object loader = reinterpret_cast<object>(arguments[0]);
|
|
|
|
object name = reinterpret_cast<object>(arguments[1]);
|
2007-09-18 23:30:09 +00:00
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
if (LIKELY(name)) {
|
2010-12-27 22:55:23 +00:00
|
|
|
THREAD_RUNTIME_ARRAY(t, char, n, stringLength(t, name) + 1);
|
2009-08-27 00:26:44 +00:00
|
|
|
stringChars(t, name, RUNTIME_ARRAY_BODY(n));
|
2010-09-17 01:43:27 +00:00
|
|
|
|
2011-03-26 01:14:21 +00:00
|
|
|
const char* name = static_cast<Finder*>
|
|
|
|
(systemClassLoaderFinder(t, loader))->urlPrefix(RUNTIME_ARRAY_BODY(n));
|
2010-09-17 01:43:27 +00:00
|
|
|
|
2011-03-26 01:14:21 +00:00
|
|
|
return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0;
|
2007-08-10 23:45:47 +00:00
|
|
|
} else {
|
2010-12-27 22:55:23 +00:00
|
|
|
throwNew(t, Machine::NullPointerExceptionType);
|
2007-08-10 23:45:47 +00:00
|
|
|
}
|
2007-07-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2010-09-14 16:49:41 +00:00
|
|
|
Avian_avian_SystemClassLoader_getClass
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2007-08-01 23:48:36 +00:00
|
|
|
{
|
2010-09-14 16:49:41 +00:00
|
|
|
return reinterpret_cast<int64_t>
|
|
|
|
(getJClass(t, reinterpret_cast<object>(arguments[0])));
|
2007-07-24 01:44:20 +00:00
|
|
|
}
|
|
|
|
|
2008-11-11 15:20:49 +00:00
|
|
|
#ifdef AVIAN_HEAPDUMP
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2009-05-26 03:36:29 +00:00
|
|
|
Avian_avian_Machine_dumpHeap
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2008-11-11 15:20:49 +00:00
|
|
|
{
|
2009-05-26 02:02:25 +00:00
|
|
|
object outputFile = reinterpret_cast<object>(*arguments);
|
2008-11-11 15:20:49 +00:00
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
unsigned length = stringLength(t, outputFile);
|
2010-12-27 22:55:23 +00:00
|
|
|
THREAD_RUNTIME_ARRAY(t, char, n, length + 1);
|
|
|
|
stringChars(t, outputFile, RUNTIME_ARRAY_BODY(n));
|
|
|
|
FILE* out = vm::fopen(RUNTIME_ARRAY_BODY(n), "wb");
|
2008-11-11 15:20:49 +00:00
|
|
|
if (out) {
|
|
|
|
{ ENTER(t, Thread::ExclusiveState);
|
|
|
|
dumpHeap(t, out);
|
|
|
|
}
|
|
|
|
fclose(out);
|
|
|
|
} else {
|
2010-12-27 22:55:23 +00:00
|
|
|
throwNew(t, Machine::RuntimeExceptionType, "file not found: %s", n);
|
2008-11-11 15:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif//AVIAN_HEAPDUMP
|
|
|
|
|
2007-09-18 23:30:09 +00:00
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2009-05-26 02:02:25 +00:00
|
|
|
Avian_java_lang_Runtime_exit
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2007-07-21 17:50:26 +00:00
|
|
|
{
|
2009-08-19 20:27:03 +00:00
|
|
|
shutDown(t);
|
|
|
|
|
2009-09-18 00:28:42 +00:00
|
|
|
t->m->system->exit(arguments[1]);
|
2007-07-21 17:50:26 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2012-10-06 21:33:24 +00:00
|
|
|
Avian_avian_avianvmresource_Handler_00024ResourceInputStream_getContentLength
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2008-07-15 15:36:52 +00:00
|
|
|
{
|
2009-05-26 02:02:25 +00:00
|
|
|
object path = reinterpret_cast<object>(*arguments);
|
2008-07-15 15:36:52 +00:00
|
|
|
|
|
|
|
if (LIKELY(path)) {
|
2010-12-27 22:55:23 +00:00
|
|
|
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1);
|
2009-08-27 00:26:44 +00:00
|
|
|
stringChars(t, path, RUNTIME_ARRAY_BODY(p));
|
2008-07-15 15:36:52 +00:00
|
|
|
|
2010-09-17 01:43:27 +00:00
|
|
|
System::Region* r = t->m->bootFinder->find(RUNTIME_ARRAY_BODY(p));
|
|
|
|
if (r == 0) {
|
|
|
|
r = t->m->appFinder->find(RUNTIME_ARRAY_BODY(p));
|
|
|
|
}
|
|
|
|
|
2008-07-15 15:36:52 +00:00
|
|
|
if (r) {
|
|
|
|
jint rSize = r->length();
|
|
|
|
r->dispose();
|
|
|
|
return rSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2012-10-06 21:33:24 +00:00
|
|
|
Avian_avian_avianvmresource_Handler_00024ResourceInputStream_open
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2007-08-10 23:45:47 +00:00
|
|
|
{
|
2009-05-26 02:02:25 +00:00
|
|
|
object path = reinterpret_cast<object>(*arguments);
|
2007-09-18 23:30:09 +00:00
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
if (LIKELY(path)) {
|
2010-12-27 22:55:23 +00:00
|
|
|
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1);
|
2009-08-27 00:26:44 +00:00
|
|
|
stringChars(t, path, RUNTIME_ARRAY_BODY(p));
|
2007-08-10 23:45:47 +00:00
|
|
|
|
2010-09-17 01:43:27 +00:00
|
|
|
System::Region* r = t->m->bootFinder->find(RUNTIME_ARRAY_BODY(p));
|
|
|
|
if (r == 0) {
|
|
|
|
r = t->m->appFinder->find(RUNTIME_ARRAY_BODY(p));
|
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<int64_t>(r);
|
2007-08-10 23:45:47 +00:00
|
|
|
} else {
|
2010-12-27 22:55:23 +00:00
|
|
|
throwNew(t, Machine::NullPointerExceptionType);
|
2007-08-10 23:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 22:11:04 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2012-10-06 21:33:24 +00:00
|
|
|
Avian_avian_avianvmresource_Handler_00024ResourceInputStream_available
|
2010-09-17 22:11:04 +00:00
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t peer; memcpy(&peer, arguments, 8);
|
|
|
|
int32_t position = arguments[2];
|
|
|
|
|
|
|
|
System::Region* region = reinterpret_cast<System::Region*>(peer);
|
|
|
|
return static_cast<jint>(region->length()) - position;
|
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2012-10-06 21:33:24 +00:00
|
|
|
Avian_avian_avianvmresource_Handler_00024ResourceInputStream_read__JI
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread*, object, uintptr_t* arguments)
|
2007-08-10 23:45:47 +00:00
|
|
|
{
|
2009-05-26 02:02:25 +00:00
|
|
|
int64_t peer; memcpy(&peer, arguments, 8);
|
|
|
|
int32_t position = arguments[2];
|
|
|
|
|
2007-09-17 00:13:36 +00:00
|
|
|
System::Region* region = reinterpret_cast<System::Region*>(peer);
|
|
|
|
if (position >= static_cast<jint>(region->length())) {
|
2007-08-10 23:45:47 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
2007-09-17 00:13:36 +00:00
|
|
|
return region->start()[position];
|
2007-08-10 23:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-26 02:02:25 +00:00
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
2012-10-06 21:33:24 +00:00
|
|
|
Avian_avian_avianvmresource_Handler_00024ResourceInputStream_read__JI_3BII
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2007-08-10 23:45:47 +00:00
|
|
|
{
|
2009-05-26 02:02:25 +00:00
|
|
|
int64_t peer; memcpy(&peer, arguments, 8);
|
|
|
|
int32_t position = arguments[2];
|
|
|
|
object buffer = reinterpret_cast<object>(arguments[3]);
|
|
|
|
int32_t offset = arguments[4];
|
|
|
|
int32_t length = arguments[5];
|
2007-09-18 23:30:09 +00:00
|
|
|
|
2007-09-13 00:21:37 +00:00
|
|
|
if (length == 0) return 0;
|
|
|
|
|
2007-09-17 00:13:36 +00:00
|
|
|
System::Region* region = reinterpret_cast<System::Region*>(peer);
|
|
|
|
if (length > static_cast<jint>(region->length()) - position) {
|
|
|
|
length = static_cast<jint>(region->length()) - position;
|
2007-08-10 23:45:47 +00:00
|
|
|
}
|
2007-09-13 00:21:37 +00:00
|
|
|
if (length <= 0) {
|
2007-08-10 23:45:47 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
2009-05-26 02:02:25 +00:00
|
|
|
memcpy(&byteArrayBody(t, buffer, offset), region->start() + position,
|
|
|
|
length);
|
2007-08-10 23:45:47 +00:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:30:09 +00:00
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2012-10-06 21:33:24 +00:00
|
|
|
Avian_avian_avianvmresource_Handler_00024ResourceInputStream_close
|
2009-05-26 02:02:25 +00:00
|
|
|
(Thread*, object, uintptr_t* arguments)
|
2007-08-10 23:45:47 +00:00
|
|
|
{
|
2009-05-26 02:02:25 +00:00
|
|
|
int64_t peer; memcpy(&peer, arguments, 8);
|
2007-09-17 00:13:36 +00:00
|
|
|
reinterpret_cast<System::Region*>(peer)->dispose();
|
2007-08-10 23:45:47 +00:00
|
|
|
}
|
2009-05-06 00:29:05 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2009-05-23 22:15:06 +00:00
|
|
|
Avian_avian_Continuations_callWithCurrentContinuation
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2009-05-06 00:29:05 +00:00
|
|
|
{
|
|
|
|
t->m->processor->callWithCurrentContinuation
|
|
|
|
(t, reinterpret_cast<object>(*arguments));
|
|
|
|
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
|
2009-05-23 22:15:06 +00:00
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_avian_Continuations_dynamicWind2
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
t->m->processor->dynamicWind
|
|
|
|
(t, reinterpret_cast<object>(arguments[0]),
|
|
|
|
reinterpret_cast<object>(arguments[1]),
|
|
|
|
reinterpret_cast<object>(arguments[2]));
|
|
|
|
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
|
2009-05-06 00:29:05 +00:00
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2009-05-16 08:03:03 +00:00
|
|
|
Avian_avian_Continuations_00024Continuation_handleResult
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2009-05-06 00:29:05 +00:00
|
|
|
{
|
|
|
|
t->m->processor->feedResultToContinuation
|
|
|
|
(t, reinterpret_cast<object>(arguments[0]),
|
|
|
|
reinterpret_cast<object>(arguments[1]));
|
|
|
|
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2009-05-16 08:03:03 +00:00
|
|
|
Avian_avian_Continuations_00024Continuation_handleException
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2009-05-06 00:29:05 +00:00
|
|
|
{
|
|
|
|
t->m->processor->feedExceptionToContinuation
|
|
|
|
(t, reinterpret_cast<object>(arguments[0]),
|
|
|
|
reinterpret_cast<object>(arguments[1]));
|
|
|
|
|
|
|
|
abort(t);
|
|
|
|
}
|
2009-09-19 22:21:15 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_avian_Singleton_getObject
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<int64_t>
|
|
|
|
(singletonObject(t, reinterpret_cast<object>(arguments[0]), arguments[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_avian_Singleton_getInt
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return singletonValue
|
|
|
|
(t, reinterpret_cast<object>(arguments[0]), arguments[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_avian_Singleton_getLong
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t v;
|
2009-10-20 19:38:05 +00:00
|
|
|
memcpy(&v, &singletonValue
|
|
|
|
(t, reinterpret_cast<object>(arguments[0]), arguments[1]), 8);
|
2009-09-19 22:21:15 +00:00
|
|
|
return v;
|
|
|
|
}
|
2012-03-06 20:07:59 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_allocateMemory
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
2012-05-03 00:00:12 +00:00
|
|
|
int64_t size; memcpy(&size, arguments + 1, 8);
|
|
|
|
void* p = malloc(size);
|
2012-03-06 20:07:59 +00:00
|
|
|
if (p) {
|
|
|
|
return reinterpret_cast<int64_t>(p);
|
|
|
|
} else {
|
|
|
|
throwNew(t, Machine::OutOfMemoryErrorType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_freeMemory
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
2012-05-03 00:00:12 +00:00
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
2012-03-06 20:07:59 +00:00
|
|
|
if (p) {
|
2012-05-03 00:00:12 +00:00
|
|
|
free(reinterpret_cast<void*>(p));
|
2012-03-06 20:07:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_setMemory
|
2012-03-14 17:54:03 +00:00
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
2012-03-06 20:07:59 +00:00
|
|
|
{
|
2012-03-14 17:54:03 +00:00
|
|
|
object base = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
int64_t count; memcpy(&count, arguments + 4, 8);
|
|
|
|
int8_t value = arguments[6];
|
|
|
|
|
|
|
|
PROTECT(t, base);
|
|
|
|
|
|
|
|
ACQUIRE(t, t->m->referenceLock);
|
|
|
|
|
|
|
|
if (base) {
|
|
|
|
memset(&cast<int8_t>(base, offset), value, count);
|
|
|
|
} else {
|
|
|
|
memset(reinterpret_cast<int8_t*>(offset), value, count);
|
|
|
|
}
|
2012-03-06 20:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NB: The following primitive get/put methods are only used by the
|
|
|
|
// interpreter. The JIT/AOT compiler implements them as intrinsics,
|
|
|
|
// so these versions will be ignored.
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putByte__JB
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
int8_t v = arguments[3];
|
|
|
|
|
|
|
|
*reinterpret_cast<int8_t*>(p) = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putShort__JS
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
int16_t v = arguments[3];
|
|
|
|
|
|
|
|
*reinterpret_cast<int16_t*>(p) = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putChar__JC
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putShort__JS(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putInt__JI
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
int32_t v = arguments[3];
|
|
|
|
|
|
|
|
*reinterpret_cast<int32_t*>(p) = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putFloat__JF
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putInt__JI(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putLong__JJ
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
int64_t v; memcpy(&v, arguments + 3, 8);
|
|
|
|
|
|
|
|
*reinterpret_cast<int64_t*>(p) = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putDouble__JD
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putLong__JJ(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putAddress__JJ
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
int64_t v; memcpy(&v, arguments + 3, 8);
|
|
|
|
|
|
|
|
*reinterpret_cast<intptr_t*>(p) = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getByte__J
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
|
|
|
|
return *reinterpret_cast<int8_t*>(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getShort__J
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
|
|
|
|
return *reinterpret_cast<int16_t*>(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getChar__J
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return Avian_sun_misc_Unsafe_getShort__J(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getInt__J
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
|
|
|
|
return *reinterpret_cast<int32_t*>(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getFloat__J
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return Avian_sun_misc_Unsafe_getInt__J(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getLong__J
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
|
|
|
|
return *reinterpret_cast<int64_t*>(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getDouble__J
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return Avian_sun_misc_Unsafe_getLong__J(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getAddress__J
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int64_t p; memcpy(&p, arguments + 1, 8);
|
|
|
|
|
|
|
|
return *reinterpret_cast<intptr_t*>(p);
|
|
|
|
}
|
2012-08-11 12:56:19 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_copyMemory
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object srcBase = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t srcOffset; memcpy(&srcOffset, arguments + 2, 8);
|
|
|
|
object dstBase = reinterpret_cast<object>(arguments[4]);
|
|
|
|
int64_t dstOffset; memcpy(&dstOffset, arguments + 5, 8);
|
|
|
|
int64_t count; memcpy(&count, arguments + 7, 8);
|
|
|
|
|
|
|
|
PROTECT(t, srcBase);
|
|
|
|
PROTECT(t, dstBase);
|
|
|
|
|
|
|
|
ACQUIRE(t, t->m->referenceLock);
|
|
|
|
|
|
|
|
void* src = srcBase
|
|
|
|
? &cast<uint8_t>(srcBase, srcOffset)
|
|
|
|
: reinterpret_cast<uint8_t*>(srcOffset);
|
|
|
|
|
|
|
|
void* dst = dstBase
|
|
|
|
? &cast<uint8_t>(dstBase, dstOffset)
|
|
|
|
: reinterpret_cast<uint8_t*>(dstOffset);
|
|
|
|
|
|
|
|
memcpy(dst, src, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_arrayBaseOffset
|
|
|
|
(Thread*, object, uintptr_t*)
|
|
|
|
{
|
|
|
|
return ArrayBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT int64_t JNICALL
|
|
|
|
Avian_java_nio_FixedArrayByteBuffer_allocateFixed
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
int capacity = arguments[0];
|
|
|
|
object address = reinterpret_cast<object>(arguments[1]);
|
|
|
|
PROTECT(t, address);
|
|
|
|
|
|
|
|
object array = allocate3
|
|
|
|
(t, t->m->heap, Machine::FixedAllocation, ArrayBody + capacity, false);
|
|
|
|
|
|
|
|
setObjectClass(t, array, type(t, Machine::ByteArrayType));
|
|
|
|
byteArrayLength(t, array) = capacity;
|
|
|
|
|
|
|
|
longArrayBody(t, address, 0) = reinterpret_cast<intptr_t>(array) + ArrayBody;
|
|
|
|
|
|
|
|
return reinterpret_cast<intptr_t>(array);
|
|
|
|
}
|