Merge branch 'wip' of oss.readytalk.com:/var/local/git/avian into wip

This commit is contained in:
jet 2009-12-23 09:26:17 -07:00
commit 77990b9489
83 changed files with 778 additions and 181 deletions

View File

@ -90,8 +90,8 @@ import java.util.concurrent.Callable;
* <h3>Winding, Unwinding, and Rewinding</h3>
*
* <p>Traditionally, Java provides one way to wind the execution stack
* (recursive method calls) and two ways to unwind it (normal returns
* and exception unwinding). With continuations, we add a new way to
* (method calls) and two ways to unwind it (normal returns and
* exception unwinding). With continuations, we add a new way to
* rewind the stack and a new way to unwind it.
*
* <p>The call stack of a continuation may share frames with other
@ -149,7 +149,7 @@ public class Continuations {
*
* <p>If <code>thunk.call()</code> calls a continuation (directly or
* via a subroutine) which does not include the current call to
* <code>dynamicWind<code>, <code>after.run()</code> will be called
* <code>dynamicWind</code>, <code>after.run()</code> will be called
* before control passes to that continuation. If this call throws
* an exception, the exception will propagate to the current caller
* of <code>dynamicWind</code>.

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2009, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -29,7 +29,7 @@ public class SystemClassLoader extends ClassLoader {
protected native Class findClass(String name) throws ClassNotFoundException;
protected native Class findLoadedClass(String name);
protected native Class reallyFindLoadedClass(String name);
private native boolean resourceExists(String name);

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -170,7 +170,7 @@ map(JNIEnv* e, const char* path)
void* data = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
if (data) {
void* p = allocate(e, sizeof(Mapping));
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
result = new (p)
Mapping(static_cast<uint8_t*>(data), size, file, mapping);
}
@ -186,7 +186,7 @@ map(JNIEnv* e, const char* path)
CloseHandle(file);
}
}
if (result == 0 and not e->ExceptionOccurred()) {
if (result == 0 and not e->ExceptionCheck()) {
throwNew(e, "java/io/IOException", "%d", GetLastError());
}
return result;
@ -256,14 +256,14 @@ map(JNIEnv* e, const char* path)
void* data = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (data) {
void* p = allocate(e, sizeof(Mapping));
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
result = new (p) Mapping(static_cast<uint8_t*>(data), s.st_size);
}
}
}
close(fd);
}
if (result == 0 and not e->ExceptionOccurred()) {
if (result == 0 and not e->ExceptionCheck()) {
throwNewErrno(e, "java/io/IOException");
}
return result;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -167,17 +167,17 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass,
makePipe(e, in);
SetHandleInformation(in[0], HANDLE_FLAG_INHERIT, 0);
jlong inDescriptor = static_cast<jlong>(descriptor(e, in[0]));
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
e->SetLongArrayRegion(process, 1, 1, &inDescriptor);
makePipe(e, out);
SetHandleInformation(out[1], HANDLE_FLAG_INHERIT, 0);
jlong outDescriptor = static_cast<jlong>(descriptor(e, out[1]));
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
e->SetLongArrayRegion(process, 2, 1, &outDescriptor);
makePipe(e, err);
SetHandleInformation(err[0], HANDLE_FLAG_INHERIT, 0);
jlong errDescriptor = static_cast<jlong>(descriptor(e, err[0]));
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
e->SetLongArrayRegion(process, 3, 1, &errDescriptor);
PROCESS_INFORMATION pi;
@ -249,19 +249,19 @@ Java_java_lang_Runtime_exec(JNIEnv* e, jclass,
int msg[] = { -1, -1 };
makePipe(e, in);
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
jlong inDescriptor = static_cast<jlong>(in[0]);
e->SetLongArrayRegion(process, 1, 1, &inDescriptor);
makePipe(e, out);
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
jlong outDescriptor = static_cast<jlong>(out[1]);
e->SetLongArrayRegion(process, 1, 1, &outDescriptor);
makePipe(e, err);
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
jlong errDescriptor = static_cast<jlong>(err[0]);
e->SetLongArrayRegion(process, 1, 1, &errDescriptor);
makePipe(e, msg);
if(e->ExceptionOccurred()) return;
if(e->ExceptionCheck()) return;
if(fcntl(msg[1], F_SETFD, FD_CLOEXEC) != 0) {
throwNewErrno(e, "java/io/IOException");
return;
@ -393,7 +393,8 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name,
} else if (strcmp(chars, "user.home") == 0) {
# ifdef _MSC_VER
WCHAR buffer[MAX_PATH];
if (_wgetenv_s(0, buffer, MAX_PATH, L"USERPROFILE") == 0) {
size_t needed;
if (_wgetenv_s(&needed, buffer, MAX_PATH, L"USERPROFILE") == 0) {
r = e->NewString(reinterpret_cast<jchar*>(buffer), lstrlenW(buffer));
} else {
r = 0;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -332,11 +332,11 @@ Java_java_nio_channels_ServerSocketChannel_natDoListen(JNIEnv *e,
{
int s = makeSocket(e);
if (s < 0) return s;
if (e->ExceptionOccurred()) return 0;
if (e->ExceptionCheck()) return 0;
sockaddr_in address;
init(e, &address, host, port);
if (e->ExceptionOccurred()) return 0;
if (e->ExceptionCheck()) return 0;
::doListen(e, s, &address);
return s;
@ -369,13 +369,13 @@ Java_java_nio_channels_SocketChannel_natDoConnect(JNIEnv *e,
jbooleanArray retVal)
{
int s = makeSocket(e);
if (e->ExceptionOccurred()) return 0;
if (e->ExceptionCheck()) return 0;
setBlocking(e, s, blocking);
sockaddr_in address;
init(e, &address, host, port);
if (e->ExceptionOccurred()) return 0;
if (e->ExceptionCheck()) return 0;
jboolean connected = ::doConnect(e, s, &address);
e->SetBooleanArrayRegion(retVal, 0, 1, &connected);

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -20,6 +20,11 @@ Java_java_util_zip_Inflater_make
(JNIEnv* e, jclass, jboolean nowrap)
{
z_stream* s = static_cast<z_stream*>(malloc(sizeof(z_stream)));
if (s == 0) {
throwNew(e, "java/lang/OutOfMemoryError", 0);
return 0;
}
memset(s, 0, sizeof(z_stream));
int r = inflateInit2(s, (nowrap ? -15 : 15));
@ -80,3 +85,74 @@ Java_java_util_zip_Inflater_inflate
e->SetIntArrayRegion(results, 0, 3, resultArray);
}
extern "C" JNIEXPORT jlong JNICALL
Java_java_util_zip_Deflater_make
(JNIEnv* e, jclass, jboolean nowrap, jint level)
{
z_stream* s = static_cast<z_stream*>(malloc(sizeof(z_stream)));
if (s == 0) {
throwNew(e, "java/lang/OutOfMemoryError", 0);
return 0;
}
memset(s, 0, sizeof(z_stream));
int r = deflateInit2(s, level, (nowrap ? -15 : 15));
if (r != Z_OK) {
free(s);
throwNew(e, "java/lang/RuntimeException", zError(r));
return 0;
}
return reinterpret_cast<jlong>(s);
}
extern "C" JNIEXPORT void JNICALL
Java_java_util_zip_Deflater_dispose(JNIEnv*, jclass, jlong peer)
{
z_stream* s = reinterpret_cast<z_stream*>(peer);
deflateEnd(s);
free(s);
}
extern "C" JNIEXPORT void JNICALL
Java_java_util_zip_Deflater_deflate
(JNIEnv* e, jclass, jlong peer,
jbyteArray input, jint inputOffset, jint inputLength,
jbyteArray output, jint outputOffset, jint outputLength,
jintArray results)
{
z_stream* s = reinterpret_cast<z_stream*>(peer);
jbyte* in = static_cast<jbyte*>(malloc(inputLength));
if (in == 0) {
throwNew(e, "java/lang/OutOfMemoryError", 0);
return;
}
jbyte* out = static_cast<jbyte*>(malloc(outputLength));
if (out == 0) {
free(in);
throwNew(e, "java/lang/OutOfMemoryError", 0);
return;
}
e->GetByteArrayRegion(input, inputOffset, inputLength, in);
s->next_in = reinterpret_cast<Bytef*>(in);
s->avail_in = inputLength;
s->next_out = reinterpret_cast<Bytef*>(out);
s->avail_out = outputLength;
int r = deflate(s, Z_SYNC_FLUSH);
jint resultArray[3]
= { r, inputLength - s->avail_in, outputLength - s->avail_out };
free(in);
e->SetByteArrayRegion(output, outputOffset, resultArray[2], out);
free(out);
e->SetIntArrayRegion(results, 0, 3, resultArray);
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -49,8 +49,10 @@ public abstract class ClassLoader {
throw new ClassNotFoundException();
}
protected Class findLoadedClass(String name) {
return null;
protected abstract Class reallyFindLoadedClass(String name);
protected final Class findLoadedClass(String name) {
return reallyFindLoadedClass(name);
}
public Class loadClass(String name) throws ClassNotFoundException {

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -185,7 +185,7 @@ public final class String
}
private static Object decodeUTF8(byte[] s8, int offset, int length) {
Object buf = new byte[s8.length];
Object buf = new byte[length];
boolean isMultiByte = false;
int i=offset, j=0;
while(i < offset+length) {
@ -195,14 +195,14 @@ public final class String
decodeUTF8_insert(buf, j++, x);
} else if((x & 0x0e0) == 0x0c0) { // 2 byte char
if(!isMultiByte) {
buf = decodeUTF8_widen(buf, j, s8.length-1);
buf = decodeUTF8_widen(buf, j, length-1);
isMultiByte = true;
}
int y = s8[i++];
decodeUTF8_insert(buf, j++, ((x & 0x1f) << 6) | (y & 0x3f));
} else if((x & 0x0f0) == 0x0e0) { // 3 byte char
if(!isMultiByte) {
buf = decodeUTF8_widen(buf, j, s8.length-2);
buf = decodeUTF8_widen(buf, j, length-2);
isMultiByte = true;
}
int y = s8[i++]; int z = s8[i++];

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -10,13 +10,20 @@
package java.lang;
import avian.Cell;
public class ThreadGroup implements Thread.UncaughtExceptionHandler {
private final ThreadGroup parent;
final ThreadGroup parent; // package private for GNU Classpath compatibility
private final String name;
private Cell<ThreadGroup> subgroups;
public ThreadGroup(ThreadGroup parent, String name) {
this.parent = parent;
this.name = name;
synchronized (parent) {
parent.subgroups = new Cell(this, subgroups);
}
}
public ThreadGroup(String name) {
@ -36,4 +43,75 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
}
}
}
public ThreadGroup getParent() {
return parent;
}
public String getName() {
return name;
}
public int activeCount() {
int allCount = Thread.activeCount();
Thread[] all = new Thread[allCount];
allCount = Thread.enumerate(all);
int count = 0;
for (int i = 0; i < allCount; ++i) {
if (parentOf(all[i].getThreadGroup())) {
++ count;
}
}
return count;
}
public int enumerate(Thread[] threads) {
return enumerate(threads, true);
}
public int enumerate(Thread[] threads, boolean recurse) {
int allCount = Thread.activeCount();
Thread[] all = new Thread[allCount];
allCount = Thread.enumerate(all);
int count = 0;
for (int i = 0; i < allCount && count < threads.length; ++i) {
Thread t = all[i];
ThreadGroup g = t.getThreadGroup();
if (g == this || (recurse && parentOf(g))) {
threads[count++] = t;
}
}
return count;
}
public boolean parentOf(ThreadGroup g) {
for (; g != null; g = g.parent) {
if (g == this) {
return true;
}
}
return false;
}
public int enumerate(ThreadGroup[] groups, boolean recurse) {
return enumerate(groups, recurse, 0);
}
private int enumerate(ThreadGroup[] groups, boolean recurse, int count) {
for (Cell<ThreadGroup> c = subgroups; c != null && count < groups.length;
c = c.next)
{
ThreadGroup g = c.value;
groups[count++] = g;
if (recurse) {
count = g.enumerate(groups, true, count);
}
}
return count;
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -42,6 +42,10 @@ public class Constructor<T> extends AccessibleObject
return method.getParameterTypes();
}
public Class[] getExceptionTypes() {
return method.getExceptionTypes();
}
public int getModifiers() {
return method.getModifiers();
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -82,6 +82,14 @@ public class Proxy {
}
}
public static boolean isProxyClass(Class c) {
return c.getName().startsWith("Proxy-");
}
public static InvocationHandler getInvocationHandler(Object proxy) {
return ((Proxy) proxy).h;
}
private static void set4(byte[] array, int offset, int v) {
array[offset ] = (byte) ((v >>> 24) & 0xFF);
array[offset + 1] = (byte) ((v >>> 16) & 0xFF);

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -0,0 +1,149 @@
/* Copyright (c) 2009, Avian Contributors
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. */
package java.util.zip;
public class Deflater {
private static final int DEFAULT_LEVEL = 6; // default compression level (6 is default for gzip)
private static final int Z_OK = 0;
private static final int Z_STREAM_END = 1;
private static final int Z_NEED_DICT = 2;
// static {
// System.loadLibrary("natives");
// }
private long peer;
private byte[] input;
private int offset;
private int length;
private boolean needDictionary;
private boolean finished;
private final boolean nowrap;
public Deflater(boolean nowrap) {
this.nowrap = nowrap;
peer = make(nowrap, DEFAULT_LEVEL);
}
public Deflater() {
this(false);
}
private void check() {
if (peer == 0) {
throw new IllegalStateException();
}
}
private static native long make(boolean nowrap, int level);
public boolean finished() {
return finished;
}
public boolean needsDictionary() {
return needDictionary;
}
public boolean needsInput() {
return getRemaining() == 0;
}
public int getRemaining() {
return length;
}
public void setLevel(int level) throws IllegalArgumentException {
if (level < 0 || level > 9) {
throw new IllegalArgumentException("Valid compression levels are 0-9");
}
dispose(peer);
peer = make(nowrap, level);
}
public void setInput(byte[] input) {
setInput(input, 0, input.length);
}
public void setInput(byte[] input, int offset, int length) {
this.input = input;
this.offset = offset;
this.length = length;
}
public void reset() {
dispose();
peer = make(nowrap, DEFAULT_LEVEL);
input = null;
offset = length = 0;
needDictionary = finished = false;
}
public int deflate(byte[] output) throws DataFormatException {
return deflate(output, 0, output.length);
}
public int deflate(byte[] output, int offset, int length)
throws DataFormatException
{
final int zlibResult = 0;
final int inputCount = 1;
final int outputCount = 2;
if (peer == 0) {
throw new IllegalStateException();
}
if (input == null || output == null) {
throw new NullPointerException();
}
int[] results = new int[3];
deflate(peer,
input, this.offset, this.length,
output, offset, length, results);
if (results[zlibResult] < 0) {
throw new DataFormatException();
}
switch (results[zlibResult]) {
case Z_NEED_DICT:
needDictionary = true;
break;
case Z_STREAM_END:
finished = true;
break;
}
this.offset += results[inputCount];
this.length -= results[inputCount];
return results[outputCount];
}
private static native void deflate
(long peer,
byte[] input, int inputOffset, int inputLength,
byte[] output, int outputOffset, int outputLength,
int[] results);
public void dispose() {
if (peer != 0) {
dispose(peer);
peer = 0;
}
}
private static native void dispose(long peer);
}

View File

@ -0,0 +1,75 @@
/* Copyright (c) 2009, Avian Contributors
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. */
package java.util.zip;
import java.io.OutputStream;
import java.io.IOException;
public class DeflaterOutputStream extends OutputStream {
private final OutputStream out;
private final Deflater deflater;
private final byte[] buffer;
public DeflaterOutputStream(OutputStream out, Deflater deflater, int bufferSize)
{
this.out = out;
this.deflater = deflater;
this.buffer = new byte[bufferSize];
}
public DeflaterOutputStream(OutputStream out, Deflater deflater) {
this(out, deflater, 4 * 1024);
}
public DeflaterOutputStream(OutputStream out) {
this(out, new Deflater());
}
public void write(int b) throws IOException {
byte[] buffer = new byte[1];
buffer[0] = (byte)(b & 0xff);
write(buffer, 0, 1);
}
public void write(byte[] b, int offset, int length) throws IOException {
// error condition checking
if (deflater.finished()) {
throw new IOException("Already at end of stream");
} else if (offset < 0) {
throw new IndexOutOfBoundsException("Offset can't be less than zero");
} else if (length < 0) {
throw new IndexOutOfBoundsException("Length can't be less than zero");
} else if (b.length - (offset + length) < 0) {
throw new IndexOutOfBoundsException("Offset + Length is larger than the input byte array");
} else if (length == 0) {
return;
}
for (int i = 0; i < length; i+= buffer.length) {
deflater.setInput(b, offset + i, Math.min(buffer.length, length - i));
while (deflater.getRemaining() > 0) {
try {
int len = deflater.deflate(buffer, 0, buffer.length);
if (len > 0) {
out.write(buffer, 0, len);
}
} catch (DataFormatException e) {
e.printStackTrace();
}
}
}
}
public void close() throws IOException {
out.close();
deflater.dispose();
}
}

View File

@ -59,6 +59,10 @@ public class Inflater {
public int getRemaining() {
return length;
}
public void setInput(byte[] input) {
setInput(input, 0, input.length);
}
public void setInput(byte[] input, int offset, int length) {
this.input = input;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,7 +1,7 @@
MAKEFLAGS = -s
name = avian
version = 0.2
version = 0.3
build-arch := $(shell uname -m | sed 's/^i.86$$/i386/')
ifeq (Power,$(filter Power,$(build-arch)))
@ -54,7 +54,7 @@ ifdef gnu
gnu-object-dep = $(build)/gnu-object.dep
gnu-cflags = -DBOOT_BUILTINS=\"javaio,javalang,javalangreflect,javamath,javanet,javanio,javautil\" -DAVIAN_GNU
gnu-lflags = -lgmp
gnu-objects := $(shell find $(build)/gnu-objects -name "*.o")
gnu-objects = $(shell find $(build)/gnu-objects -name "*.o")
endif
root := $(shell (cd .. && pwd))
@ -171,6 +171,12 @@ ifeq ($(platform),darwin)
asmflags += -arch i386
lflags += -arch i386
endif
ifeq ($(arch),x86_64)
cflags += -arch x86_64
asmflags += -arch x86_64
lflags += -arch x86_64
endif
endif
ifeq ($(platform),windows)
@ -265,19 +271,17 @@ ifdef msvc
-I"$(windows-java-home)/include/win32"
shared = -dll
lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \
-DEFAULTLIB:zlib -MANIFEST
-DEFAULTLIB:zlib -MANIFEST -debug
output = -Fo$(1)
ifeq ($(mode),debug)
cflags += -Od -Zi -MDd
lflags += -debug
endif
ifeq ($(mode),debug-fast)
cflags += -Od -Zi -DNDEBUG
lflags += -debug
endif
ifeq ($(mode),fast)
cflags += -Ob2it -GL -Zi -DNDEBUG
cflags += -O2 -GL -Zi -DNDEBUG
lflags += -LTCG
endif
ifeq ($(mode),small)
@ -383,7 +387,13 @@ bootimage-object = $(native-build)/bootimage-bin.o
ifeq ($(bootimage),true)
ifneq ($(build-arch),$(arch))
error "can't cross-build a bootimage"
$(error "bootimage cross-builds not yet supported")
endif
ifeq ($(arch),x86_64)
ifneq ($(build-platform),$(platform))
$(error "bootimage cross-builds not yet supported")
endif
endif
vm-classpath-object = $(bootimage-object)
@ -434,7 +444,6 @@ gnu-overrides = \
avian/*.class \
avian/resource/*.class \
java/lang/Class.class \
java/lang/Class\$$*.class \
java/lang/Enum.class \
java/lang/InheritableThreadLocal.class \
java/lang/Object.class \
@ -457,7 +466,9 @@ gnu-overrides = \
java/lang/reflect/AccessibleObject.class \
java/lang/reflect/Constructor.class \
java/lang/reflect/Field.class \
java/lang/reflect/Method.class
java/lang/reflect/Method.class \
java/lang/reflect/Proxy.class \
java/lang/reflect/Proxy\$$*.class
test-sources = $(wildcard $(test)/*.java)
test-classes = $(call java-classes,$(test-sources),$(test),$(test-build))

View File

@ -12,13 +12,13 @@ on Mac OS X:
$ build/darwin-i386/avian -cp build/test Hello
on Windows (MSYS):
$ git clone git://oss.readytalk.com/win32.git ../win32
$ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07"
$ make
$ build/windows-i386/avian -cp build/test Hello
on Windows (Cygwin):
$ git clone git://oss.readytalk.com/win32.git ../win32
$ export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.6.0_07"
$ make
$ build/windows-i386/avian -cp build/test Hello
@ -96,7 +96,9 @@ certain flags described below, all of which are optional.
* bootimage - if true, create a boot image containing the pre-parsed
class library and ahead-of-time compiled methods. This option is
only valid for process=compile builds.
only valid for process=compile builds. Note that you may need to
specify both build-arch=x86_64 and arch=x86_64 on 64-bit systems
where "uname -m" prints "i386".
default: false
* heapdump - if true, implement avian.Machine.dumpHeap(String),
@ -151,6 +153,63 @@ directory containing the avian directory)
This gives you the Windows JNI headers, zlib headers and library, and
a few other useful libraries like OpenSSL, libjpeg, and libpng.
There's also a win64 repository for 64-bit builds:
$ git clone git://oss.readytalk.com/win64.git
Building with Microsoft the Visual C++ Compiler
-----------------------------------------------
You can also build using the MSVC compiler, which makes debugging with
tools like WinDbg and Visual Studio much easier. Note that you will
still need to have GCC installed - MSVC is only used to compile the
C++ portions of the VM, while the assembly code and helper tools are
built using GCC.
The MSVC build has been tested with Visual Studio Express Edition
versions 8 and 9. Other versions may also work.
To build with MSVC, install Cygwin as described above and set the
following environment variables:
$ export PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/IDE:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/BIN:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/Tools:/cygdrive/c/WINDOWS/Microsoft.NET/Framework/v3.5:/cygdrive/c/WINDOWS/Microsoft.NET/Framework/v2.0.50727:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/VCPackages:/cygdrive/c/Program Files/Microsoft SDKs/Windows/v6.0A/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem"
$ export LIBPATH="C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;"
$ export VCINSTALLDIR="C:\Program Files\Microsoft Visual Studio 9.0\VC"
$ export LIB="C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib;"
$ export INCLUDE="C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\include;"
Adjust these definitions as necessary according to your MSVC
installation.
Finally, build with the msvc flag set to the MSVC tool directory:
$ make msvc="/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC"
Building with GNU Classpath
---------------------------
** Please note that this feature is still under development and is
neither complete nor well-tested. **
By default, Avian uses its own lightweight class library. However,
that library only contains a relatively small subset of the classes
and methods included in the JRE. If your application requires
features beyond that subset, you may want to tell Avian to use GNU
Classpath instead. To do so, specify the directory where Classpath is
installed, e.g.:
$ make clean
$ make gnu=/usr/local/classpath-0.98
This build will use the classes and native code from Classpath, except
that certain core classes are replaced with implementations from the
Avian class library for compatibility with the VM.
Installing
@ -247,13 +306,13 @@ main(int ac, const char** av)
JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = e->FindClass("Hello");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0);
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
for (int i = 1; i < ac; ++i) {
e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i]));
}
@ -265,7 +324,7 @@ main(int ac, const char** av)
}
int exitCode = 0;
if (e->ExceptionOccurred()) {
if (e->ExceptionCheck()) {
exitCode = -1;
e->ExceptionDescribe();
}
@ -449,13 +508,13 @@ main(int ac, const char** av)
JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = e->FindClass("Hello");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(ac-1, stringClass, 0);
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
for (int i = 1; i < ac; ++i) {
e->SetObjectArrayElement(a, i-1, e->NewStringUTF(av[i]));
}
@ -467,7 +526,7 @@ main(int ac, const char** av)
}
int exitCode = 0;
if (e->ExceptionOccurred()) {
if (e->ExceptionCheck()) {
exitCode = -1;
e->ExceptionDescribe();
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -64,12 +64,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
object method = arrayBody(t, classMethodTable(t, c), i);
if ((methodCode(t, method) or (methodFlags(t, method) & ACC_NATIVE))
and ((methodName == 0
or strcmp
or ::strcmp
(reinterpret_cast<char*>
(&byteArrayBody
(t, vm::methodName(t, method), 0)), methodName) == 0)
and (methodSpec == 0
or strcmp
or ::strcmp
(reinterpret_cast<char*>
(&byteArrayBody
(t, vm::methodSpec(t, method), 0)), methodSpec)

View File

@ -200,8 +200,8 @@ Avian_avian_SystemClassLoader_defineClass
t->m->heap->free(buffer, length);
if (c) {
PROTECT(t, c);
if (getClassLoaderMap(t, loader) == 0) {
PROTECT(t, c);
object map = makeHashMap(t, 0, 0);
set(t, loader, ClassLoaderMap, map);
}
@ -214,7 +214,7 @@ Avian_avian_SystemClassLoader_defineClass
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_avian_SystemClassLoader_findLoadedClass
Avian_avian_SystemClassLoader_reallyFindLoadedClass
(Thread* t, object, uintptr_t* arguments)
{
object name = reinterpret_cast<object>(arguments[1]);

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -22,7 +22,7 @@
#ifdef __x86_64__
#ifdef __MINGW32__
#if defined __MINGW32__ || defined __CYGWIN32__
#define CALLEE_SAVED_REGISTER_FOOTPRINT 64
@ -107,9 +107,9 @@ GLOBAL(vmJumpAndInvoke):
// %rdx: address
// %r8 : base
// %r9 : (unused)
// 8(%rsp): argumentFootprint
// 16(%rsp): arguments
// 24(%rsp): frameSize
// 40(%rsp): argumentFootprint
// 48(%rsp): arguments
// 56(%rsp): frameSize
movq %r8,%rbp
@ -118,20 +118,20 @@ GLOBAL(vmJumpAndInvoke):
movq %rbp,%r9
// allocate new frame, adding room for callee-saved registers
movl 24(%rsp),%eax
movl 56(%rsp),%eax
subq %rax,%r9
subq $CALLEE_SAVED_REGISTER_FOOTPRINT,%r9
movq %rcx,%rbx
// set return address
movq vmInvoke_returnAddress@GOTPCREL(%rip),%r10
leaq GLOBAL(vmInvoke_returnAddress)(%rip),%r10
movq %r10,(%r9)
// copy arguments into place
movq $0,%r11
movq 16(%rsp),%r8
movq 8(%rsp),%rax
movl 48(%rsp),%r8d
movl 40(%rsp),%eax
jmp LOCAL(vmJumpAndInvoke_argumentTest)
LOCAL(vmJumpAndInvoke_argumentLoop):
@ -154,7 +154,7 @@ LOCAL(vmJumpAndInvoke_argumentTest):
int3
#endif // not AVIAN_CONTINUATIONS
#else // not __MINGW32__
#else // not __MINGW32__ || __CYGWIN32__
#define CALLEE_SAVED_REGISTER_FOOTPRINT 48
@ -252,7 +252,7 @@ GLOBAL(vmJumpAndInvoke):
movq %rdi,%rbx
// set return address
movq vmInvoke_returnAddress@GOTPCREL(%rip),%r10
movq GLOBAL(vmInvoke_returnAddress)@GOTPCREL(%rip),%r10
movq %r10,(%rcx)
// copy arguments into place
@ -279,7 +279,7 @@ LOCAL(vmJumpAndInvoke_argumentTest):
int3
#endif // not AVIAN_CONTINUATIONS
#endif // not __MINGW32__
#endif // not __MINGW32__ || __CYGWIN32__
#elif defined __i386__
@ -396,9 +396,18 @@ GLOBAL(vmJumpAndInvoke):
movl 4(%esp),%ebx
// set return address
#if defined __MINGW32__ || defined __CYGWIN32__
movl $vmInvoke_returnAddress,%esi
#else
call LOCAL(getPC)
# if defined __APPLE__
LOCAL(vmJumpAndInvoke_offset):
leal vmInvoke_returnAddress-LOCAL(vmJumpAndInvoke_offset)(%esi),%esi
# else
addl $_GLOBAL_OFFSET_TABLE_,%esi
movl vmInvoke_returnAddress@GOT(%esi),%esi
# endif
#endif
movl %esi,(%ecx)
// copy arguments into place

View File

@ -1886,7 +1886,7 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetBase,
*targetIp = ip;
*targetBase = base;
*targetStack = static_cast<void**>(stack)
+ t->arch->frameReturnAddressSize();;
+ t->arch->frameReturnAddressSize();
}
}
@ -2955,8 +2955,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
{
#define MATCH(name, constant) \
(byteArrayLength(t, name) == sizeof(constant) \
and strcmp(reinterpret_cast<char*>(&byteArrayBody(t, name, 0)), \
constant) == 0)
and ::strcmp(reinterpret_cast<char*>(&byteArrayBody(t, name, 0)), \
constant) == 0)
object className = vm::className(t, methodClass(t, target));
if (UNLIKELY(MATCH(className, "java/lang/Math"))) {
@ -6973,6 +6973,8 @@ class MyProcessor: public Processor {
nativeThunk(0),
bootNativeThunk(0),
aioobThunk(0),
thunkTable(0),
bootThunkTable(0),
callTable(0),
methodTree(0),
methodTreeSentinal(0),
@ -6985,6 +6987,7 @@ class MyProcessor: public Processor {
bootImage(0),
codeAllocator(s, 0, 0),
thunkSize(0),
bootThunkSize(0),
callTableSize(0),
useNativeFeatures(useNativeFeatures)
{ }
@ -7119,11 +7122,20 @@ class MyProcessor: public Processor {
{
if (o) {
MyThread* t = static_cast<MyThread*>(vmt);
PROTECT(t, o);
for (Reference* r = t->reference; r; r = r->next) {
if (r->target == o) {
acquire(t, r);
return &(r->target);
}
}
Reference* r = new (t->m->heap->allocate(sizeof(Reference)))
Reference(o, &(t->reference));
acquire(t, r);
return &(r->target);
} else {
return 0;
@ -7134,7 +7146,7 @@ class MyProcessor: public Processor {
disposeLocalReference(Thread* t, object* r)
{
if (r) {
vm::dispose(t, reinterpret_cast<Reference*>(r));
release(t, reinterpret_cast<Reference*>(r));
}
}
@ -7298,8 +7310,14 @@ class MyProcessor: public Processor {
uint8_t* thunkStart = p->thunkTable;
uint8_t* thunkEnd = thunkStart + (p->thunkSize * ThunkCount);
if (static_cast<uint8_t*>(ip) >= thunkStart
and static_cast<uint8_t*>(ip) < thunkEnd)
uint8_t* bootThunkStart = p->bootThunkTable;
uint8_t* bootThunkEnd = bootThunkStart
+ (p->bootThunkSize * ThunkCount);
if ((static_cast<uint8_t*>(ip) >= thunkStart
and static_cast<uint8_t*>(ip) < thunkEnd)
or (static_cast<uint8_t*>(ip) >= bootThunkStart
and static_cast<uint8_t*>(ip) < bootThunkEnd))
{
target->ip = t->arch->frameIp(stack);
target->base = base;
@ -7462,6 +7480,7 @@ class MyProcessor: public Processor {
uint8_t* bootNativeThunk;
uint8_t* aioobThunk;
uint8_t* thunkTable;
uint8_t* bootThunkTable;
object callTable;
object methodTree;
object methodTreeSentinal;
@ -7475,6 +7494,7 @@ class MyProcessor: public Processor {
SegFaultHandler segFaultHandler;
FixedAllocator codeAllocator;
unsigned thunkSize;
unsigned bootThunkSize;
unsigned callTableSize;
bool useNativeFeatures;
};
@ -7748,6 +7768,8 @@ fixupThunks(MyThread* t, BootImage* image, uint8_t* code)
p->bootDefaultThunk = code + image->defaultThunk;
p->bootNativeThunk = code + image->nativeThunk;
p->bootThunkTable = code + image->thunkTable;
p->bootThunkSize = image->thunkSize;
updateCall(t, LongCall, code + image->compileMethodCall,
voidPointer(local::compileMethod));

View File

@ -2156,7 +2156,8 @@ class MemorySite: public Site {
virtual SiteMask mask(Context* c) {
return SiteMask(1 << MemoryOperand, 0, (base == c->arch->stack())
? offsetToFrameIndex(c, offset) : NoFrameIndex);
? static_cast<int>(offsetToFrameIndex(c, offset))
: NoFrameIndex);
}
virtual SiteMask nextWordMask(Context* c, unsigned index) {
@ -2439,6 +2440,19 @@ maybeMove(Context* c, Read* read, bool intersectRead, bool includeNextWord,
}
if (cost) {
if (DebugMoves) {
char srcb[256]; src->toString(c, srcb, 256);
char dstb[256]; dst->toString(c, dstb, 256);
fprintf(stderr, "maybe move %s to %s for %p to %p\n",
srcb, dstb, value, value);
}
src->freeze(c, value);
addSite(c, value, dst);
src->thaw(c, value);
if (not src->match(c, srcMask)) {
src->freeze(c, value);
dst->freeze(c, value);
@ -2450,6 +2464,8 @@ maybeMove(Context* c, Read* read, bool intersectRead, bool includeNextWord,
Site* tmp = pickTargetSite(c, &tmpRead, true);
addSite(c, value, tmp);
move(c, value, src, tmp);
dst->thaw(c, value);
@ -2851,10 +2867,9 @@ move(Context* c, Value* value, Site* src, Site* dst)
srcb, dstb, value, value);
}
assert(c, findSite(c, value, dst));
src->freeze(c, value);
addSite(c, value, dst);
dst->freeze(c, value);
unsigned srcSize;
@ -3197,7 +3212,7 @@ class CallEvent: public Event {
}
for (unsigned i = 0; i < stackArgumentFootprint; ++i) {
Value* v = arguments[i];
Value* v = RUNTIME_ARRAY_BODY(arguments)[i];
if (v) {
int frameIndex = i + frameOffset;
@ -5279,10 +5294,6 @@ resolveSourceSites(Context* c, Event* e, SiteRecordList* frozen, Site** sites)
Site* s = pickSourceSite
(c, r, 0, 0, &mask, true, false, true, acceptForResolve);
if (s == 0) {
s = pickSourceSite
(c, r, 0, 0, &mask, false, false, true, acceptForResolve);
}
if (s) {
if (DebugControl) {
@ -5317,12 +5328,9 @@ resolveTargetSites(Context* c, Event* e, SiteRecordList* frozen, Site** sites)
Site* s = pickSourceSite
(c, r, 0, 0, &mask, true, true, true, acceptForResolve);
if (s == 0) {
s = pickSourceSite
(c, r, 0, 0, &mask, false, true, true, acceptForResolve);
if (s == 0) {
s = maybeMove(c, v, mask, false, true, ResolveRegisterReserveCount);
}
s = maybeMove(c, v, mask, false, true, ResolveRegisterReserveCount);
}
freeze(c, frozen, s, v);

View File

@ -1,3 +1,13 @@
/* Copyright (c) 2009, Avian Contributors
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. */
#ifdef __x86_64__
#define THREAD_CONTINUATION 176
@ -42,7 +52,11 @@ LOCAL(vmInvoke_continuationTest):
// set the return address to vmInvoke_returnAddress
movq CONTINUATION_RETURN_ADDRESS_OFFSET(%rcx),%rdi
movq vmInvoke_returnAddress@GOTPCREL(%rip),%r10
#if defined __MINGW32__ || defined __CYGWIN32__
leaq GLOBAL(vmInvoke_returnAddress)(%rip),%r10
#else
movq GLOBAL(vmInvoke_returnAddress)@GOTPCREL(%rip),%r10
#endif
movq %r10,(%rsp,%rdi,1)
// save the current base pointer in the frame and update it
@ -93,9 +107,11 @@ LOCAL(vmInvoke_exit):
cmpl $0,%ecx
je LOCAL(vmInvoke_exit)
// allocate a frame of size (continuation.length * BYTES_PER_WORD)
// allocate a frame of size (continuation.length * BYTES_PER_WORD),
// plus stack alignment padding
movl CONTINUATION_LENGTH(%ecx),%esi
shll $2,%esi
leal 8(%esi),%esi
subl %esi,%esp
// copy the continuation body into the frame
@ -121,9 +137,18 @@ LOCAL(vmInvoke_continuationTest):
// set the return address to vmInvoke_returnAddress
movl CONTINUATION_RETURN_ADDRESS_OFFSET(%ecx),%edi
#if defined __MINGW32__ || defined __CYGWIN32__
movl $vmInvoke_returnAddress,%esi
#else
call LOCAL(getPC)
# if defined __APPLE__
LOCAL(vmInvoke_offset):
leal vmInvoke_returnAddress-LOCAL(vmInvoke_offset)(%esi),%esi
# else
addl $_GLOBAL_OFFSET_TABLE_,%esi
movl vmInvoke_returnAddress@GOT(%esi),%esi
# endif
#endif
movl %esi,(%esp,%edi,1)
// save the current base pointer in the frame and update it

View File

@ -351,7 +351,7 @@ Avian_java_lang_VMClassLoader_getPrimitiveClass
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_java_lang_ClassLoader_defineClass
Avian_avian_SystemClassLoader_defineClass
(Thread*, object, uintptr_t*);
extern "C" JNIEXPORT int64_t JNICALL
@ -367,7 +367,7 @@ Avian_java_lang_VMClassLoader_defineClass
// fprintf(stderr, "define class %s in %p\n", n,
// reinterpret_cast<void*>(arguments[0]));
return Avian_java_lang_ClassLoader_defineClass(t, 0, args);
return Avian_avian_SystemClassLoader_defineClass(t, 0, args);
}
extern "C" JNIEXPORT int64_t JNICALL

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -15,6 +15,8 @@ using namespace vm;
namespace {
namespace local {
const uintptr_t PointerShift = log(BytesPerWord);
class Context;
@ -157,7 +159,7 @@ find(Context* c, object p)
int
Set::find(object value)
{
Set::Entry* e = ::find(context, value);
Set::Entry* e = local::find(context, value);
if (e) {
return e->number;
} else {
@ -328,6 +330,8 @@ class MyHeapWalker: public HeapWalker {
HeapVisitor* visitor;
};
} // namespace local
} // namespace
namespace vm {
@ -335,7 +339,8 @@ namespace vm {
HeapWalker*
makeHeapWalker(Thread* t, HeapVisitor* v)
{
return new (t->m->heap->allocate(sizeof(MyHeapWalker))) MyHeapWalker(t, v);
return new (t->m->heap->allocate(sizeof(local::MyHeapWalker)))
local::MyHeapWalker(t, v);
}
} // namespace vm

View File

@ -506,7 +506,7 @@ resolveNativeMethodData(Thread* t, object method)
// ensure other threads see updated methodVmFlags before
// methodCode, and that the native method data is initialized
// before it is visible to those threads:
memoryBarrier();
storeStoreMemoryBarrier();
set(t, method, MethodCode, data);
} else {

View File

@ -1186,9 +1186,19 @@ NewGlobalRef(Thread* t, jobject o)
ACQUIRE(t, t->m->referenceLock);
if (o) {
for (Reference* r = t->m->jniReferences; r; r = r->next) {
if (r->target == *o) {
acquire(t, r);
return &(r->target);
}
}
Reference* r = new (t->m->heap->allocate(sizeof(Reference)))
Reference(*o, &(t->m->jniReferences));
acquire(t, r);
return &(r->target);
} else {
return 0;
@ -1203,7 +1213,7 @@ DeleteGlobalRef(Thread* t, jobject r)
ACQUIRE(t, t->m->referenceLock);
if (r) {
dispose(t, reinterpret_cast<Reference*>(r));
release(t, reinterpret_cast<Reference*>(r));
}
}

View File

@ -173,7 +173,9 @@ turnOffTheLights(Thread* t)
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
if (function) {
function(t, finalizerTarget(t, f));
}
}
for (object* p = &(t->m->tenuredFinalizers); *p;) {
@ -182,7 +184,9 @@ turnOffTheLights(Thread* t)
void (*function)(Thread*, object);
memcpy(&function, &finalizerFinalize(t, f), BytesPerWord);
function(t, finalizerTarget(t, f));
if (function) {
function(t, finalizerTarget(t, f));
}
}
Machine* m = t->m;
@ -230,7 +234,7 @@ makeJavaThread(Thread* t, Thread* parent)
if (parent) {
group = threadGroup(t, parent->javaThread);
} else {
group = makeThreadGroup(t, 0, 0);
group = makeThreadGroup(t, 0, 0, 0);
}
const unsigned NewState = 0;
@ -1848,8 +1852,9 @@ bootClass(Thread* t, Machine::Type type, int superType, uint32_t objectMask,
super = (superType >= 0 ? arrayBody(t, t->m->types, superType) : 0);
object class_ = t->m->processor->makeClass
(t, 0, BootstrapFlag, fixedSize, arrayElementSize, 0, mask, 0, 0, super, 0,
0, 0, 0, 0, 0, t->m->loader, vtableLength);
(t, 0, BootstrapFlag, fixedSize, arrayElementSize,
arrayElementSize ? 1 : 0, mask, 0, 0, super, 0, 0, 0, 0, 0, 0,
t->m->loader, vtableLength);
set(t, t->m->types, ArrayBody + (type * BytesPerWord), class_);
}
@ -1951,6 +1956,23 @@ boot(Thread* t)
classVmFlags(t, arrayBody(t, m->types, Machine::JvoidType))
|= PrimitiveFlag;
set(t, arrayBody(t, m->types, Machine::BooleanArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JbooleanType));
set(t, arrayBody(t, m->types, Machine::ByteArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JbyteType));
set(t, arrayBody(t, m->types, Machine::CharArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JcharType));
set(t, arrayBody(t, m->types, Machine::ShortArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JshortType));
set(t, arrayBody(t, m->types, Machine::IntArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JintType));
set(t, arrayBody(t, m->types, Machine::LongArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JlongType));
set(t, arrayBody(t, m->types, Machine::FloatArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JfloatType));
set(t, arrayBody(t, m->types, Machine::DoubleArrayType), ClassStaticTable,
arrayBody(t, m->types, Machine::JdoubleType));
m->classMap = makeHashMap(t, 0, 0);
m->bootstrapClassMap = makeHashMap(t, 0, 0);

View File

@ -1131,7 +1131,8 @@ class Reference {
Reference(object target, Reference** handle):
target(target),
next(*handle),
handle(handle)
handle(handle),
count(0)
{
if (next) {
next->handle = &next;
@ -1142,6 +1143,7 @@ class Reference {
object target;
Reference* next;
Reference** handle;
unsigned count;
};
class Machine {
@ -1404,6 +1406,20 @@ dispose(Thread* t, Reference* r)
t->m->heap->free(r, sizeof(*r));
}
inline void
acquire(Thread*, Reference* r)
{
++ r->count;
}
inline void
release(Thread* t, Reference* r)
{
if ((-- r->count) == 0) {
dispose(t, r);
}
}
void
collect(Thread* t, Heap::CollectionType type);

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -178,13 +178,13 @@ main(int ac, const char** av)
JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = e->FindClass(class_);
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(argc, stringClass, 0);
if (not e->ExceptionOccurred()) {
if (not e->ExceptionCheck()) {
for (int i = 0; i < argc; ++i) {
e->SetObjectArrayElement(a, i, e->NewStringUTF(argv[i]));
}
@ -196,7 +196,7 @@ main(int ac, const char** av)
}
int exitCode = 0;
if (e->ExceptionOccurred()) {
if (e->ExceptionCheck()) {
exitCode = -1;
e->ExceptionDescribe();
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided

View File

@ -8,7 +8,6 @@
There is NO WARRANTY for this software. See license.txt for
details. */
#include "types.h"
#define LOCAL(x) .L##x
@ -168,8 +167,8 @@ LOCAL(exit):
.globl GLOBAL(vmJump)
GLOBAL(vmJump):
movq %rdx,%rbp
movq 8(%rsp),%rax
movq 16(%rsp),%rdx
movq 40(%rsp),%rax
movq 48(%rsp),%rdx
movq %r8,%rsp
movq %r9,%rbx
jmp *%rcx

View File

@ -981,7 +981,7 @@ sseMoveRR(Context* c, unsigned aSize, Assembler::Register* a,
modrm(c, 0xc0, a, b);
} else {
opcode(c, 0xf2);
maybeRex(c, 8, a, b);
maybeRex(c, 4, a, b);
opcode(c, 0x0f, 0x10);
modrm(c, 0xc0, a, b);
}

View File

@ -16,6 +16,10 @@
#ifdef _MSC_VER
# include "windows.h"
# pragma push_macro("assert")
# include "intrin.h"
# pragma pop_macro("assert")
# undef interface
#endif
#ifdef ARCH_x86_32
@ -155,7 +159,23 @@ trap()
}
inline void
memoryBarrier()
programOrderMemoryBarrier()
{
#ifdef _MSC_VER
_ReadWriteBarrier();
#else
__asm__ __volatile__("": : :"memory");
#endif
}
inline void
storeStoreMemoryBarrier()
{
programOrderMemoryBarrier();
}
inline void
storeLoadMemoryBarrier()
{
#ifdef _MSC_VER
MemoryBarrier();
@ -166,28 +186,16 @@ memoryBarrier()
#endif // ARCH_x86_64
}
inline void
storeStoreMemoryBarrier()
{
__asm__ __volatile__("": : :"memory");
}
inline void
storeLoadMemoryBarrier()
{
memoryBarrier();
}
inline void
loadMemoryBarrier()
{
__asm__ __volatile__("": : :"memory");
programOrderMemoryBarrier();
}
inline void
syncInstructionCache(const void*, unsigned)
{
__asm__ __volatile__("": : :"memory");
programOrderMemoryBarrier();
}
#ifdef USE_ATOMIC_OPERATIONS

View File

@ -15,3 +15,9 @@
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, static_cast<int>(sizeof(z_stream)))
#endif
#ifdef deflateInit2
#undef deflateInit2
#define deflateInit2(strm, level, windowBits) \
deflateInit2_((strm), (level), Z_DEFLATED, (windowBits), 8, Z_DEFAULT_STRATEGY, ZLIB_VERSION, static_cast<int>(sizeof(z_stream)))
#endif