diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 8825b8ffa3..514bfc40e1 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -7,7 +7,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ - + #include "math.h" #include "stdlib.h" #include "sys/time.h" @@ -32,11 +32,13 @@ # define SO_PREFIX "" #else # define SO_PREFIX "lib" +#include "sys/utsname.h" #include "sys/wait.h" #endif #ifdef __APPLE__ # define SO_SUFFIX ".jnilib" +#include #elif defined WIN32 # define SO_SUFFIX ".dll" #else @@ -349,6 +351,14 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = e->NewStringUTF("\\"); } else if (strcmp(chars, "os.name") == 0) { r = e->NewStringUTF("Windows"); + } else if (strcmp(chars, "os.version") == 0) { + unsigned size = 32; + char buffer[size]; + OSVERSIONINFO OSversion; + OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); + ::GetVersionEx(&OSversion); + snprintf(buffer, size, "%i.%i", (int)OSversion.dwMajorVersion, (int)OSversion.dwMinorVersion); + r = e->NewStringUTF(buffer); } else if (strcmp(chars, "java.io.tmpdir") == 0) { TCHAR buffer[MAX_PATH]; GetTempPath(MAX_PATH, buffer); @@ -367,11 +377,27 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, r = e->NewStringUTF("Mac OS X"); #else r = e->NewStringUTF("Linux"); +#endif + } else if (strcmp(chars, "os.version") == 0) { +#ifdef __APPLE__ + unsigned size = 32; + char buffer[size]; + long minorVersion, majorVersion; + + Gestalt(gestaltSystemVersionMajor, &majorVersion); + Gestalt(gestaltSystemVersionMinor, &minorVersion); + + snprintf(buffer, size, "%ld.%ld", majorVersion, minorVersion); + r = e->NewStringUTF(buffer); +#else + struct utsname system_id; + uname(&system_id); + r = e->NewStringUTF(system_id.release); #endif } else if (strcmp(chars, "java.io.tmpdir") == 0) { r = e->NewStringUTF("/tmp"); } else if (strcmp(chars, "user.home") == 0) { - r = e->NewStringUTF(getenv("HOME")); + r = e->NewStringUTF(getenv("HOME")); } #endif diff --git a/classpath/java/util/LinkedList.java b/classpath/java/util/LinkedList.java index 657d245997..0fab004117 100644 --- a/classpath/java/util/LinkedList.java +++ b/classpath/java/util/LinkedList.java @@ -97,10 +97,6 @@ public class LinkedList implements List { return find(element) != null; } - public void addAll(Collection c) { - for (T t: c) add(t); - } - public boolean add(T element) { addLast(element); return true; diff --git a/makefile b/makefile index d0041344e9..fa5641f24e 100644 --- a/makefile +++ b/makefile @@ -127,7 +127,7 @@ endif ifeq ($(platform),darwin) build-cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src) - lflags = $(common-lflags) -ldl -framework CoreFoundation + lflags = $(common-lflags) -ldl -framework CoreFoundation -framework CoreServices ifeq ($(bootimage),true) bootimage-lflags = -Wl,-segprot,__BOOT,rwx,rwx endif diff --git a/src/builtin.cpp b/src/builtin.cpp index fe1cf34c6f..571f033ab0 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -27,6 +27,8 @@ search(Thread* t, object name, object (*op)(Thread*, object), bool replaceDots) { if (LIKELY(name)) { + PROTECT(t, name); + object n = makeByteArray(t, stringLength(t, name) + 1); char* s = reinterpret_cast(&byteArrayBody(t, n, 0)); stringChars(t, name, s); diff --git a/src/compile.cpp b/src/compile.cpp index d996a5c95f..9df1a10b39 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -271,7 +271,7 @@ class MyStackWalker: public Processor::StackWalker { virtual void walk(Processor::StackVisitor* v) { for (MyStackWalker it(this); it.valid();) { - MyStackWalker walker(it); + MyStackWalker walker(&it); if (not v->visit(&walker)) { break; } @@ -548,6 +548,7 @@ enum Event { IpEvent, MarkEvent, ClearEvent, + InitEvent, TraceEvent }; @@ -4183,24 +4184,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, } } +FILE* compileLog = 0; + void logCompile(MyThread* t, const void* code, unsigned size, const char* class_, const char* name, const char* spec) { - static FILE* log = 0; static bool open = false; if (not open) { open = true; const char* path = findProperty(t, "avian.jit.log"); if (path) { - log = fopen(path, "wb"); + compileLog = fopen(path, "wb"); } else if (DebugCompile) { - log = stderr; + compileLog = stderr; } } - if (log) { - fprintf(log, "%p %p %s.%s%s\n", + if (compileLog) { + fprintf(compileLog, "%p %p %s.%s%s\n", code, static_cast(code) + size, class_, name, spec); } @@ -4387,6 +4389,14 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, clearBit(roots, i); } break; + case InitEvent: { + unsigned reference = context->eventLog.get2(eventIndex); + eventIndex += 2; + + uintptr_t* tableRoots = context->rootTable + (reference * mapSize); + memcpy(roots, tableRoots, mapSize * BytesPerWord); + } break; + case TraceEvent: { TraceElement* te; context->eventLog.get(eventIndex, &te, BytesPerWord); if (DebugFrameMaps) { @@ -4710,16 +4720,8 @@ compile(MyThread* t, Allocator* allocator, Context* context) uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))]; Frame frame2(&frame, stackMap); - uintptr_t* roots = context->rootTable - + (start * frameMapSizeInWords(t, context->method)); - - for (unsigned i = 0; i < localSize(t, context->method); ++ i) { - if (getBit(roots, i)) { - frame2.set(i, Frame::Object); - } else { - frame2.set(i, Frame::Integer); - } - } + context->eventLog.append(InitEvent); + context->eventLog.append2(start); for (unsigned i = 1; i < codeMaxStack(t, methodCode(t, context->method)); @@ -5848,6 +5850,11 @@ class SegFaultHandler: public System::SignalHandler { return true; } } + + if (compileLog) { + fflush(compileLog); + } + return false; } diff --git a/src/compiler.cpp b/src/compiler.cpp index 1b9b95ca44..79cf2dacf6 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -2591,7 +2591,7 @@ unreachable(Event* event) for (Link* p = event->predecessors; p; p = p->nextPredecessor) { if (not p->predecessor->allExits()) return false; } - return true; + return event->predecessors != 0; } class ReturnEvent: public Event { diff --git a/src/heap.cpp b/src/heap.cpp index f04d5de2c3..5ec5ae724d 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -34,6 +34,12 @@ const bool Verbose2 = false; const bool Debug = false; const bool DebugFixies = false; +#ifdef NDEBUG +const bool DebugAllocation = false; +#else +const bool DebugAllocation = true; +#endif + #define ACQUIRE(x) MutexLock MAKE_NAME(monitorLock_) (x) class MutexLock { @@ -422,7 +428,9 @@ class Segment { } void dispose() { - free(context, data, (footprint(capacity())) * BytesPerWord); + if (data) { + free(context, data, (footprint(capacity())) * BytesPerWord); + } data = 0; map = 0; } @@ -1673,11 +1681,22 @@ void* tryAllocate(Context* c, unsigned size) { ACQUIRE(c->lock); + if (DebugAllocation) { + size = pad(size) + 2 * BytesPerWord; + } + if (size + c->count < c->limit) { void* p = c->system->tryAllocate(size); if (p) { c->count += size; - return p; + + if (DebugAllocation) { + static_cast(p)[0] = 0x22377322; + static_cast(p)[(size / BytesPerWord) - 1] = 0x22377322; + return static_cast(p) + 1; + } else { + return p; + } } } return 0; @@ -1686,7 +1705,21 @@ void* tryAllocate(Context* c, unsigned size) void free(Context* c, const void* p, unsigned size) { ACQUIRE(c->lock); + if (DebugAllocation) { + size = pad(size) + 2 * BytesPerWord; + + memset(const_cast(p), 0xFE, size - (2 * BytesPerWord)); + + p = static_cast(p) - 1; + + expect(c->system, static_cast(p)[0] == 0x22377322); + + expect(c->system, static_cast(p) + [(size / BytesPerWord) - 1] == 0x22377322); + } + expect(c->system, c->count >= size); + c->system->free(p); c->count -= size; } diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 199145ba6c..6bb9015bac 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -97,6 +97,14 @@ GetEnv(Machine* m, Thread** t, jint version) } } +jsize JNICALL +GetVersion(Thread* t) +{ + ENTER(t, Thread::ActiveState); + + return JNI_VERSION_1_6; +} + jsize JNICALL GetStringLength(Thread* t, jstring s) { @@ -1911,6 +1919,7 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable) memset(envTable, 0, sizeof(JNIEnvVTable)); + envTable->GetVersion = ::GetVersion; envTable->GetStringLength = ::GetStringLength; envTable->GetStringChars = ::GetStringChars; envTable->ReleaseStringChars = ::ReleaseStringChars; diff --git a/src/machine.h b/src/machine.h index a458557318..4bb5ed153d 100644 --- a/src/machine.h +++ b/src/machine.h @@ -94,6 +94,10 @@ const unsigned CompiledFlag = 1 << 1; const unsigned ConstructorFlag = 1 << 2; const unsigned FastNative = 1 << 3; +#ifndef JNI_VERSION_1_6 +#define JNI_VERSION_1_6 0x00010006 +#endif + typedef Machine JavaVM; typedef Thread JNIEnv; diff --git a/src/windows.cpp b/src/windows.cpp index 6487e5165b..300bcefc7b 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -772,7 +772,8 @@ struct MINIDUMP_USER_STREAM_INFORMATION; struct MINIDUMP_CALLBACK_INFORMATION; enum MINIDUMP_TYPE { - MiniDumpNormal = 0 + MiniDumpNormal = 0, + MiniDumpWithFullMemory = 2 }; typedef BOOL (*MiniDumpWriteDumpType) @@ -812,7 +813,7 @@ dump(LPEXCEPTION_POINTERS e, const char* directory) (GetCurrentProcess(), GetCurrentProcessId(), file, - MiniDumpNormal, + MiniDumpWithFullMemory, &exception, 0, 0);