2013-07-03 02:52:38 +00:00
|
|
|
/* Copyright (c) 2008-2013, 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. */
|
|
|
|
|
2013-02-27 20:25:50 +00:00
|
|
|
#include "avian/machine.h"
|
|
|
|
#include "avian/constants.h"
|
|
|
|
#include "avian/processor.h"
|
|
|
|
#include "avian/util.h"
|
2007-07-06 15:24:06 +00:00
|
|
|
|
2013-02-20 05:56:05 +00:00
|
|
|
#include <avian/util/runtime-array.h>
|
2013-02-11 00:51:59 +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
|
|
|
}
|
|
|
|
|
2013-12-18 18:06:15 +00:00
|
|
|
object
|
|
|
|
fieldForOffsetInClass(Thread* t, object c, unsigned offset)
|
|
|
|
{
|
|
|
|
object super = classSuper(t, c);
|
|
|
|
if (super) {
|
|
|
|
object field = fieldForOffsetInClass(t, super, offset);
|
|
|
|
if (field) {
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object table = classFieldTable(t, c);
|
|
|
|
if (table) {
|
|
|
|
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
|
|
|
|
object field = objectArrayBody(t, table, i);
|
|
|
|
if ((fieldFlags(t, field) & ACC_STATIC) == 0
|
|
|
|
and fieldOffset(t, field) == offset)
|
|
|
|
{
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
fieldForOffset(Thread* t, object o, unsigned offset)
|
|
|
|
{
|
|
|
|
object c = objectClass(t, o);
|
|
|
|
if (classVmFlags(t, c) & SingletonFlag) {
|
|
|
|
c = singletonObject(t, o, 0);
|
|
|
|
object table = classFieldTable(t, c);
|
|
|
|
if (table) {
|
|
|
|
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
|
|
|
|
object field = objectArrayBody(t, table, i);
|
|
|
|
if ((fieldFlags(t, field) & ACC_STATIC)
|
|
|
|
and fieldOffset(t, field) == offset)
|
|
|
|
{
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
abort(t);
|
|
|
|
} else {
|
|
|
|
object field = fieldForOffsetInClass(t, c, offset);
|
|
|
|
if (field) {
|
|
|
|
return field;
|
|
|
|
} else {
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 16:49:41 +00:00
|
|
|
} // namespace
|
2007-08-10 23:45:47 +00:00
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2013-02-21 22:37:17 +00:00
|
|
|
Avian_avian_Classes_initialize
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object this_ = reinterpret_cast<object>(arguments[0]);
|
|
|
|
|
|
|
|
initClass(t, this_);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2011-03-27 05:24:48 +00:00
|
|
|
Avian_avian_Classes_acquireClassLock
|
|
|
|
(Thread* t, object, uintptr_t*)
|
|
|
|
{
|
|
|
|
acquire(t, t->m->classLock);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2011-03-27 05:24:48 +00:00
|
|
|
Avian_avian_Classes_releaseClassLock
|
|
|
|
(Thread* t, object, uintptr_t*)
|
|
|
|
{
|
|
|
|
release(t, t->m->classLock);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2011-03-27 05:24:48 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-02-21 22:37:17 +00:00
|
|
|
Avian_avian_Classes_defineVMClass
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object loader = reinterpret_cast<object>(arguments[0]);
|
|
|
|
object b = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int offset = arguments[2];
|
|
|
|
int length = arguments[3];
|
|
|
|
|
|
|
|
uint8_t* buffer = static_cast<uint8_t*>
|
|
|
|
(t->m->heap->allocate(length));
|
|
|
|
|
|
|
|
THREAD_RESOURCE2(t, uint8_t*, buffer, int, length,
|
|
|
|
t->m->heap->free(buffer, length));
|
|
|
|
|
|
|
|
memcpy(buffer, &byteArrayBody(t, b, offset), length);
|
|
|
|
|
|
|
|
return reinterpret_cast<int64_t>(defineClass(t, loader, buffer, length));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-02-21 22:37:17 +00:00
|
|
|
Avian_avian_SystemClassLoader_vmClass
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<int64_t>
|
|
|
|
(jclassVmClass(t, reinterpret_cast<object>(arguments[0])));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-10-28 13:52:58 +00:00
|
|
|
Avian_avian_SystemClassLoader_00024ResourceEnumeration_nextResourceURLPrefix
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object loader = reinterpret_cast<object>(arguments[1]);
|
|
|
|
object name = reinterpret_cast<object>(arguments[2]);
|
|
|
|
object finderElementPtrPtr = reinterpret_cast<object>(arguments[3]);
|
|
|
|
|
|
|
|
if (LIKELY(name) && LIKELY(finderElementPtrPtr)) {
|
|
|
|
THREAD_RUNTIME_ARRAY(t, char, n, stringLength(t, name) + 1);
|
|
|
|
stringChars(t, name, RUNTIME_ARRAY_BODY(n));
|
|
|
|
|
|
|
|
void *&finderElementPtr = reinterpret_cast<void *&>(longArrayBody(t,
|
|
|
|
finderElementPtrPtr, 0));
|
|
|
|
const char* name = static_cast<Finder*>
|
|
|
|
(systemClassLoaderFinder(t, loader))->nextUrlPrefix(RUNTIME_ARRAY_BODY(n),
|
|
|
|
finderElementPtr);
|
|
|
|
|
|
|
|
return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0;
|
|
|
|
} else {
|
|
|
|
throwNew(t, Machine::NullPointerExceptionType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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 {
|
2013-03-04 23:00:35 +00:00
|
|
|
throwNew(t, Machine::RuntimeExceptionType, "file not found: %s",
|
|
|
|
RUNTIME_ARRAY_BODY(n));
|
2008-11-11 15:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif//AVIAN_HEAPDUMP
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2009-05-23 22:15:06 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT 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
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2009-09-19 22:21:15 +00:00
|
|
|
Avian_avian_Singleton_getObject
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<int64_t>
|
|
|
|
(singletonObject(t, reinterpret_cast<object>(arguments[0]), arguments[1]));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2009-09-19 22:21:15 +00:00
|
|
|
Avian_avian_Singleton_getInt
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return singletonValue
|
|
|
|
(t, reinterpret_cast<object>(arguments[0]), arguments[1]);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2009-09-19 22:21:15 +00:00
|
|
|
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
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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) {
|
2013-02-11 00:38:51 +00:00
|
|
|
memset(&fieldAtOffset<int8_t>(base, offset), value, count);
|
2012-03-14 17:54:03 +00:00
|
|
|
} 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.
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
Avian_sun_misc_Unsafe_putChar__JC
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putShort__JS(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
Avian_sun_misc_Unsafe_putFloat__JF
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putInt__JI(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
Avian_sun_misc_Unsafe_putDouble__JD
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putLong__JJ(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
Avian_sun_misc_Unsafe_getChar__J
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return Avian_sun_misc_Unsafe_getShort__J(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
Avian_sun_misc_Unsafe_getFloat__J
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return Avian_sun_misc_Unsafe_getInt__J(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
Avian_sun_misc_Unsafe_getDouble__J
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return Avian_sun_misc_Unsafe_getLong__J(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-03-06 20:07:59 +00:00
|
|
|
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
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2012-08-11 12:56:19 +00:00
|
|
|
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
|
2013-02-11 00:38:51 +00:00
|
|
|
? &fieldAtOffset<uint8_t>(srcBase, srcOffset)
|
2012-08-11 12:56:19 +00:00
|
|
|
: reinterpret_cast<uint8_t*>(srcOffset);
|
|
|
|
|
|
|
|
void* dst = dstBase
|
2013-02-11 00:38:51 +00:00
|
|
|
? &fieldAtOffset<uint8_t>(dstBase, dstOffset)
|
2012-08-11 12:56:19 +00:00
|
|
|
: reinterpret_cast<uint8_t*>(dstOffset);
|
|
|
|
|
|
|
|
memcpy(dst, src, count);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-08-11 12:56:19 +00:00
|
|
|
Avian_sun_misc_Unsafe_arrayBaseOffset
|
|
|
|
(Thread*, object, uintptr_t*)
|
|
|
|
{
|
|
|
|
return ArrayBody;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2012-08-11 12:56:19 +00:00
|
|
|
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);
|
|
|
|
}
|
2013-02-20 17:22:40 +00:00
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_getObject
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
|
|
|
|
return fieldAtOffset<uintptr_t>(o, offset);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_putObject
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
uintptr_t value = arguments[4];
|
|
|
|
|
|
|
|
set(t, o, offset, reinterpret_cast<object>(value));
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:00:53 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putObjectVolatile
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
object value = reinterpret_cast<object>(arguments[4]);
|
|
|
|
|
|
|
|
storeStoreMemoryBarrier();
|
|
|
|
set(t, o, offset, reinterpret_cast<object>(value));
|
|
|
|
storeLoadMemoryBarrier();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putOrderedObject
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putObjectVolatile(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2014-03-03 21:51:43 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getObjectVolatile
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
|
|
|
|
uintptr_t value = fieldAtOffset<uintptr_t>(o, offset);
|
|
|
|
loadMemoryBarrier();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_compareAndSwapObject
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object target = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
uintptr_t expect = arguments[4];
|
|
|
|
uintptr_t update = arguments[5];
|
|
|
|
|
|
|
|
bool success = atomicCompareAndSwap
|
|
|
|
(&fieldAtOffset<uintptr_t>(target, offset), expect, update);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
mark(t, target, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-02-20 17:22:40 +00:00
|
|
|
Avian_sun_misc_Unsafe_compareAndSwapInt
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object target = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
uint32_t expect = arguments[4];
|
|
|
|
uint32_t update = arguments[5];
|
|
|
|
|
|
|
|
return atomicCompareAndSwap32
|
|
|
|
(&fieldAtOffset<uint32_t>(target, offset), expect, update);
|
|
|
|
}
|
2013-02-22 18:06:49 +00:00
|
|
|
|
2013-12-12 18:12:38 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_compareAndSwapLong
|
|
|
|
(Thread* t UNUSED, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object target = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
uint64_t expect; memcpy(&expect, arguments + 4, 8);
|
|
|
|
uint64_t update; memcpy(&update, arguments + 6, 8);
|
|
|
|
|
|
|
|
#ifdef AVIAN_HAS_CAS64
|
|
|
|
return atomicCompareAndSwap64
|
|
|
|
(&fieldAtOffset<uint64_t>(target, offset), expect, update);
|
|
|
|
#else
|
2013-12-18 18:06:15 +00:00
|
|
|
ACQUIRE_FIELD_FOR_WRITE(t, fieldForOffset(t, target, offset));
|
2013-12-12 18:12:38 +00:00
|
|
|
if (fieldAtOffset<uint64_t>(target, offset) == expect) {
|
|
|
|
fieldAtOffset<uint64_t>(target, offset) = update;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-18 18:06:15 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getLongVolatile
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
|
|
|
|
object field;
|
|
|
|
if (BytesPerWord < 8) {
|
|
|
|
field = fieldForOffset(t, o, offset);
|
|
|
|
|
|
|
|
PROTECT(t, field);
|
|
|
|
acquire(t, field);
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t result = fieldAtOffset<int64_t>(o, offset);
|
|
|
|
|
|
|
|
if (BytesPerWord < 8) {
|
|
|
|
release(t, field);
|
|
|
|
} else {
|
|
|
|
loadMemoryBarrier();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-03 00:49:56 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putLongVolatile
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
int64_t value; memcpy(&value, arguments + 4, 8);
|
|
|
|
|
|
|
|
object field;
|
|
|
|
if (BytesPerWord < 8) {
|
|
|
|
field = fieldForOffset(t, o, offset);
|
|
|
|
|
|
|
|
PROTECT(t, field);
|
|
|
|
acquire(t, field);
|
|
|
|
} else {
|
|
|
|
storeStoreMemoryBarrier();
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldAtOffset<int64_t>(o, offset) = value;
|
|
|
|
|
|
|
|
if (BytesPerWord < 8) {
|
|
|
|
release(t, field);
|
|
|
|
} else {
|
|
|
|
storeLoadMemoryBarrier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_putOrderedLong
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
// todo: we might be able to use weaker barriers here than
|
|
|
|
// putLongVolatile does
|
|
|
|
Avian_sun_misc_Unsafe_putLongVolatile(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_unpark
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object thread = reinterpret_cast<object>(arguments[1]);
|
|
|
|
|
|
|
|
monitorAcquire(t, interruptLock(t, thread));
|
|
|
|
threadUnparked(t, thread) = true;
|
|
|
|
monitorNotify(t, interruptLock(t, thread));
|
|
|
|
monitorRelease(t, interruptLock(t, thread));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_park
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
bool absolute = arguments[1];
|
|
|
|
int64_t time; memcpy(&time, arguments + 2, 8);
|
|
|
|
|
|
|
|
int64_t then = t->m->system->now();
|
|
|
|
|
|
|
|
if (absolute) {
|
|
|
|
time -= then;
|
|
|
|
if (time <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (time) {
|
|
|
|
// if not absolute, interpret time as nanoseconds, but make sure
|
|
|
|
// it doesn't become zero when we convert to milliseconds, since
|
|
|
|
// zero is interpreted as infinity below
|
|
|
|
time = (time / (1000 * 1000)) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
monitorAcquire(t, interruptLock(t, t->javaThread));
|
2013-05-01 04:45:08 +00:00
|
|
|
bool interrupted = false;
|
2013-04-23 19:47:15 +00:00
|
|
|
while (time >= 0
|
|
|
|
and (not (threadUnparked(t, t->javaThread)
|
2013-05-01 04:45:08 +00:00
|
|
|
or threadInterrupted(t, t->javaThread)
|
|
|
|
or (interrupted = monitorWait
|
|
|
|
(t, interruptLock(t, t->javaThread), time)))))
|
2013-04-23 19:47:15 +00:00
|
|
|
{
|
|
|
|
int64_t now = t->m->system->now();
|
|
|
|
time -= now - then;
|
|
|
|
then = now;
|
|
|
|
|
|
|
|
if (time == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-01 04:45:08 +00:00
|
|
|
if (interrupted) {
|
|
|
|
threadInterrupted(t, t->javaThread) = true;
|
|
|
|
}
|
2013-04-23 19:47:15 +00:00
|
|
|
threadUnparked(t, t->javaThread) = false;
|
|
|
|
monitorRelease(t, interruptLock(t, t->javaThread));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_putIntVolatile
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
int32_t value = arguments[4];
|
|
|
|
|
|
|
|
storeStoreMemoryBarrier();
|
|
|
|
fieldAtOffset<int32_t>(o, offset) = value;
|
|
|
|
storeLoadMemoryBarrier();
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
2013-04-23 19:47:15 +00:00
|
|
|
Avian_sun_misc_Unsafe_putOrderedInt
|
|
|
|
(Thread* t, object method, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
Avian_sun_misc_Unsafe_putIntVolatile(t, method, arguments);
|
|
|
|
}
|
|
|
|
|
2014-03-03 21:51:43 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_getIntVolatile
|
|
|
|
(Thread*, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
object o = reinterpret_cast<object>(arguments[1]);
|
|
|
|
int64_t offset; memcpy(&offset, arguments + 2, 8);
|
|
|
|
|
|
|
|
int32_t result = fieldAtOffset<int32_t>(o, offset);
|
|
|
|
loadMemoryBarrier();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-06 03:28:08 +00:00
|
|
|
extern "C" AVIAN_EXPORT void JNICALL
|
|
|
|
Avian_sun_misc_Unsafe_throwException
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
vm::throw_(t, reinterpret_cast<object>(arguments[1]));
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:35:10 +00:00
|
|
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
2013-02-22 18:06:49 +00:00
|
|
|
Avian_avian_Classes_primitiveClass
|
|
|
|
(Thread* t, object, uintptr_t* arguments)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<int64_t>(primitiveClass(t, arguments[0]));
|
|
|
|
}
|