Commit Graph

442 Commits

Author SHA1 Message Date
Joshua Warner
7bd3ea1892 add simple disassembler for debugging 2012-05-22 13:58:53 -06:00
Joel Dice
0addd8c814 update copyright years 2012-05-11 17:43:27 -06:00
Joel Dice
5ef5158bc1 Merge remote branch 'oss/master' into jdk7 2012-05-04 18:54:31 -06:00
Joel Dice
ea4e0a2f5d fix a couple of subtle Thread.getStackTrace bugs
The first problem was that, on x86, we failed to properly keep track
of whether to expect the return address to be on the stack or not when
unwinding through a frame.  We were relying on a "stackLimit" pointer
to tell us whether we were looking at the most recently-called frame
by comparing it with the stack pointer for that frame.  That was
inaccurate in the case of a thread executing at the beginning of a
method before a new frame is allocated, in which case the most recent
two frames share a stack pointer, confusing the unwinder.  The
solution involves keeping track of how many frames we've looked at
while walking the stack.

The other problem was that compareIpToMethodBounds assumed every
method was followed by at least one byte of padding before the next
method started.  That assumption was usually valid because we were
storing the size following method code prior to the code itself.
However, the last method of an AOT-compiled code image is not followed
by any such method header and may instead be followed directly by
native code with no intervening padding.  In that case, we risk
interpreting that native code as part of the preceding method, with
potentially bizarre results.

The reason for the compareIpToMethodBounds assumption was that methods
which throw exceptions as their last instruction generate a
non-returning call, which nonetheless push a return address on the
stack which points past the end of the method, and the unwinder needs
to know that return address belongs to that method.  A better solution
is to add an extra trap instruction to the end of such methods, which
is what this patch does.
2012-05-04 18:51:58 -06:00
Joel Dice
994098baf1 make find[Field|Method]InClass non-inline functions
It seems that GCC 4.6.1 gets confused at LTO time when we take the
address of inline functions, so I'm switching them to non-inline
linkage to make it happy.
2012-03-26 18:09:35 -06:00
Joel Dice
2ee3771125 make find[Field|Method]InClass non-inline functions
It seems that GCC 4.6.1 gets confused at LTO time when we take the
address of inline functions, so I'm switching them to non-inline
linkage to make it happy.
2012-03-26 18:06:16 -06:00
Joel Dice
674c560494 fix static field alignment calculation
The previous code caused overlap between 64-bit fields and subsequent
fields under certain circumstances on 32-bit systems.
2012-03-17 22:45:35 -06:00
Joel Dice
d78247ab9a implement -Xss command line option 2012-03-14 12:36:42 -06:00
Joel Dice
1d77b06540 fix recent throwNew/makeThrowable regression
6fceca9 introduced a string formatting regression in these methods,
which this commit fixes.
2012-03-03 18:37:27 -07:00
Joel Dice
5203cb5dcf implement JNI methods NewWeakGlobalRef and DeleteWeakGlobalRef 2012-02-29 11:51:30 -07:00
Joel Dice
6fceca940f fix makeByteArray and makeString for strings longer than 256 characters 2012-02-29 11:49:13 -07:00
Joel Dice
c6ac66e45a fix bug in isAssignableFrom such that primitive array types were considered to be subclasses of the Object array type 2012-02-27 18:16:01 -07:00
Joel Dice
33976d1ba4 ensure debug helper functions are retained by linker
Apple's linker tends to remove functions which are never called, which
is not what we want for e.g. vmPrintTrace, since that function is only
intended to be called interactively from within GDB.
2012-02-04 15:42:19 -07:00
Joel Dice
be6896b8a0 avoid running out of OS resources due to zombie thread accumulation (part 2)
My previous attempt wasn't quite sufficient, since it was too late to
call join on a thread which had already exited given the code was
written to aggressively dispose of system handles as soon as the
thread exited.  The solution is to delay disposing these handles until
after we're able to join the thread.
2012-02-03 17:20:20 -07:00
Joel Dice
c3256c2874 avoid running out of OS resources due to zombie thread accumulation
The bug here is that when a thread exits and becomes a "zombie", the
OS resources associated with it are not necessarily released until we
actually join and dispose of that thread.  Since that only happens
during garbage collection, and collection normally only happens in
response to heap memory pressure, there's no guarantee that we'll GC
frequently enough to clean up zombies promptly and avoid running out
of resources.

The solution is to force a GC whenever we start a new thread and there
are at least N zombies waiting to be disposed, where N=16 for now.
2012-02-03 12:00:02 -07:00
Joel Dice
929315e1f2 avoid crash when parsing certain abstract classes which declare no methods 2012-01-13 16:51:39 -07:00
Joel Dice
0aa5755187 call C library free directly instead of System::free where possible
There was a subtle race condition in the VM shutdown process such that
a System::Thread would be disposed after the System instance it was
created under has been disposed, in which case doing a virtual call to
System::free with that instance would potentially cause a crash.  The
solution is to just call the C library version of free directly, since
that's all System::free does.
2012-01-12 11:00:58 -07:00
Joel Dice
e4c1f923b5 fix GC safety bug in resolveObjectArrayClass
The call to getClassRuntimeData may trigger a GC, so we must mark the
local variables to be visited.
2011-11-18 08:38:19 -07:00
Joel Dice
4d0b127989 support multiple sequential VM instances with bootimage build
Until now, the bootimage build hasn't supported using the Java
invocation API to create a VM, destroy it, and create another in the
same process.  Ideally, we would be able to create multiple VMs
simultaneously without any interference between them.  In fact, Avian
is designed to support this for the most part, but there are a few
places we use global, mutable state which prevent this from working.
Most notably, the bootimage is modified in-place at runtime, so the
best we can do without extensive changes is to clean up the bootimage
when the VM is destroyed so it's ready for later instances.  Hence
this commit.

Ultimately, we can move towards a fully reentrant VM by making the
bootimage immutable, but this will require some care to avoid
performance regressions.  Another challenge is our Posix signal
handlers, which currently rely on a global handle to the VM, since you
can't, to my knowledge, pass a context pointer when registering a
signal handler.  Thread local variables won't necessarily help, since
a thread might attatch to more than one VM at a time.
2011-11-10 13:33:36 -07:00
Joel Dice
248ff26581 fix thinko in machine.cpp 2011-10-03 08:04:58 -06:00
Joel Dice
4e4d109787 fix regression in static field offset calculation
One of the changes in commit 5b4f179 broke this calculation.
2011-09-28 11:12:21 -06:00
Joel Dice
c537dcfd34 generate read-only code image in bootimage build
This avoids the requirement of putting the code image in a
section/segment which is both writable and executable, which is good
for security and avoids trouble with systems like iOS which disallow
such things.

The implementation relies on relative addressing such that the offset
of the desired address is fixed as a compile-time constant relative to
the start of the memory area of interest (e.g. the code image, heap
image, or thunk table).  At runtime, the base pointer to the memory
area is retrieved from the thread structure and added to the offset to
compute the final address.  Using the thread pointer allows us to
generate read-only, position-independent code while avoiding the use
of IP-relative addressing, which is not available on all
architectures.
2011-09-20 16:30:30 -06:00
Joel Dice
67300c229a change local variable name to avoid shadowing another variable 2011-08-31 21:15:41 -06:00
Joel Dice
5b4f17997f progress towards cross-architecture bootimage builds
This monster commit is the first step towards supporting
cross-architecture bootimage builds.  The challenge is to build a heap
and code image for the target platform where the word size and
endianess may differ from those of the build architecture.  That means
the memory layout of objects may differ due to alignment and size
differences, so we can't just copy objects into the heap image
unchanged; we must copy field by field, resizing values, reversing
endianess and shifting offsets as necessary.

This commit also removes POD (plain old data) type support from the
type generator because it added a lot of complication and little
value.
2011-08-29 19:00:17 -06:00
Joel Dice
4b9cb4f4e4 enable JMX support for openjdk-src build and implement GetInputArgumentArray 2011-08-05 18:06:29 -06:00
Joel Dice
08d4fddbb4 handle case of class with no methods in classInitializer 2011-07-17 19:51:48 -06:00
Joel Dice
e3662f13a9 update copyright years and increment version number 2011-07-13 08:25:21 -06:00
Joel Dice
19d5022456 fix GC safety bugs in getClassAddendum and makeArrayClass 2011-07-09 18:01:00 -06:00
Joel Dice
ec4568d806 handle strings of arbitrary size in makeByteArray 2011-07-09 18:00:19 -06:00
Joel Dice
7c30e44601 add appropriate memory barriers to double-checked locking code 2011-04-10 14:46:53 -06:00
Joel Dice
00b829b8e8 fix Class.getDeclaredMethods
Internally, the VM augments the method tables for abstract classes
with any inherited abstract methods to make code simpler elsewhere,
but that means we can't use that table to construct the result of
Class.getDeclaredMethods since it would include methods not actually
declared in the class.  This commit ensures that we preserve and use
the original, un-augmented table for that purpose.
2011-04-09 21:20:56 -06:00
Joel Dice
b3d65fab9b fix handling of interfaces in isAssignableFrom
The old version was both incorrect (in the case where both arguments
are interfaces) and inefficient.
2011-04-09 21:09:59 -06:00
Joel Dice
60db8cc047 add some commented-out debug code to defineClass
When uncommented, this code will write each defined class to disk,
which allows one to examine e.g. dynamically-generated classes using
e.g. javap.
2011-04-08 18:46:43 -06:00
Joel Dice
af9288f4ee don't abort when parsing malformed UTF8 strings
Previously, we would abort the process if we encountered a truncated
multibyte character in parseUtf8NonAscii (called by the JNI method
NewStringUTF).  Now we simply terminate the string at that point.
2011-04-07 14:26:54 -06:00
Joel Dice
b0ae6343ad provide proper implementations of JVM_GetDeclaredClasses, JVM_GetDeclaringClass 2011-03-31 19:47:26 -06:00
Joel Dice
ef86530080 call static initializer of superclass before that of class itself
Also, assume any class which has an ancestor class which has a static
initializer needs initialization even if it doesn't have one itself,
per the Java Language Spec.
2011-03-31 19:43:49 -06:00
Joel Dice
1c7abe782d specify valid code source for system classes
This enables use of a class's protection domain to determine what JAR
or directory it came from.
2011-03-31 19:38:44 -06:00
Joel Dice
8d9412c1e8 remove redundant statement in parseUtf8
VM heap allocated memory is already zero'd out, so there's no need to
explicitly end strings with a null character.
2011-03-31 19:10:20 -06:00
Joel Dice
9fe41b2afc only return declared interfaces from Class.getInterfaces
The result of Class.getInterfaces should not include interfaces
declared to be implemented/extended by superclasses/superinterfaces,
only those declared by the class itself.  This is important because it
influences how java.io.ObjectStreamClass calculates serial version
IDs.
2011-03-27 20:29:31 -06:00
Joel Dice
ad79bbcbd5 update class loader map when creating new array class
This ensures that we don't create redundant array classes later.
2011-03-26 23:21:37 -06:00
Joel Dice
ba0cc803a6 implement various JVM_* methods
This includes a proper implementation of JVM_ActiveProcessorCount, as
well as JVM_SetLength and JVM_NewMultiArray.  Also, we now accept up
to JNI_VERSION_1_6 in JVM_IsSupportedJNIVersion.
2011-03-26 11:15:52 -06:00
Joel Dice
838cf9fdd1 avoid calling doCollect recursively
We must not allocate heap objects from doCollect, since it might
trigger a GC while one is already in progress, which can cause trouble
when we're still queuing up objects to finalize, among other things.
To avoid this, I've added extra fields to the finalizer and cleaner
types which we can use to link instances up during GC without
allocating new memory.
2011-03-25 19:11:38 -06:00
Joel Dice
61552b6b8a check for and handle instances of sun.misc.Cleaner during GC
OpenJDK uses an alternative to Object.finalize for resource cleanup in
the form of sun.misc.Cleaner.  Normally, OpenJDK's
java.lang.ref.Reference.ReferenceHandler thread handles this, calling
Cleaner.clean on any instances it finds in its "pending" queue.
However, Avian handles reference queuing internally, so it never
actually adds anything to that queue, so the VM must call
Cleaner.clean itself.
2011-03-19 15:10:52 -06:00
Joel Dice
7004c0ddf3 various fixes and additions to increase app compatiblity
The main changes here are:

  * fixes for runtime annotation support

  * proper support for runtime generic type introspection

  * throw NoClassDefFoundErrors instead of ClassNotFoundExceptions
    where appropriate
2011-03-17 21:42:15 -06:00
Joel Dice
366dfc009c fix mode=stress thinko and GC safety issue in machine.cpp 2011-03-17 08:49:41 -06:00
Joel Dice
7152c3fdb3 handle volatile fields properly in JNI Get/Set methods
This commit ensures that we use the proper memory barriers or locking
necessary to preserve volatile semantics for such fields when accessed
or updated via JNI.
2011-03-15 19:34:00 -06:00
Joel Dice
453ceb42ab implement lazy class/field/method resolution in JIT compiler
Unlike the interpreter, the JIT compiler tries to resolve all the
symbols referenced by a method when compiling that method.  However,
this can backfire if a symbol cannot be resolved: we end up throwing
an e.g. NoClassDefFoundError for code which may never be executed.
This is particularly troublesome for code which supports multiple
APIs, choosing one at runtime.

The solution is to defer to stub code for symbols which can't be
resolved at JIT compile time.  Such a stub will try again at runtime
to resolve the needed symbol and throw an appropriate error if it
still can't be found.
2011-03-15 18:07:13 -06:00
Joel Dice
e5ecb5b549 add optional avian.error.log system property
This property may be used to specify a file name to use for printing
stack traces for unhandled exceptions.  The default is stderr.
2011-03-15 17:27:17 -06:00
Joel Dice
8fb9523de5 don't try to print null exception trace in printTrace
It is possible to create an Exception with no stack trace by
overriding Throwable.fillInStackTrace, so we can't assume any given
instance will have one.
2011-03-04 15:58:10 -07:00
Joel Dice
25f1a9f1e8 fix Thread::exit/Thread::dispose race condition
There was a race between these two functions such that one thread A
would run dispose on thread B just before thread B finishes exit, with
the result that Thread::lock and/or Thread::systemThread would be
disposed twice, resulting in a crash.
2011-02-28 10:14:01 -07:00
Joel Dice
468edb97d2 work around GCC name mangling bug
It seems that older versions of GCC (4.0 and older, at least) generate
assembly files with duplicate symbols for function templates which
differ only by the attributes of the templated types.  Newer versions
have no such problem, but we need to support both, hence the
workaround in this commit of using a dedicated, non-template "alias"
function where we previously used "cast<alias_t>".
2011-02-14 11:47:59 -07:00
Joel Dice
8d50d0fd76 fix aliasing bug in util.cpp
We use a template function called "cast" to get raw access to fields
in in the VM.  In particular, we use this function in util.cpp to
treat reference fields as intptr_t fields so we can use the least
significant bit as the red/black flag in red/black tree nodes.
Unfortunately, this runs afoul of the type aliasing rules in C/C++,
and the compiler is permitted to optimize in a way that assumes such
aliasing cannot occur.  Such optimization caused all the nodes in the
tree to be black, leading to extremely unbalanced trees and thus slow
performance.

The fix in this case is to use the __may_alias__ attribute to tell the
compiler we're doing something devious.  I've also used this technique
to avoid other potential aliasing problems.  There may be others
lurking, so a complete audit of the VM might be a good idea.
2011-02-11 21:57:27 -07:00
Joel Dice
cb7dc1aeef fix various regressions due to 0.5 work 2011-02-11 21:13:11 -07:00
Joel Dice
51a1081adc remove unused Heap::Client::outOfMemory method
The heap-dump-on-OOM feature has been moved to the collect function.
2011-02-02 08:46:20 -07:00
Joel Dice
fff51bad06 more progress on PowerPC build
Also, hide frame mapping for stack unwinding (which is still
incomplete) in x86.cpp, since no other platform needs it.
2011-01-30 14:14:57 -07:00
Joel Dice
b47dfdf5bd remove debug logging 2011-01-27 21:05:22 -07:00
Joel Dice
b7157c802a fix continuations=true build 2011-01-27 11:54:41 -07:00
Joel Dice
e16d5f83af Merge remote branch 'origin/master' into r0.5 2011-01-25 17:30:21 -07:00
Joel Dice
c855224d14 fix VM abort when ClassLoader.defineClass is used in bootimage build
When loading a class which extends another class that contained a
field of primitive array type using defineClass in a bootimage=true
build, the VM was unable to find the primitive array class, and
makeArrayClass refused to create one since it should already have
existed.

The problem was that the bootimage=true build uses an empty
Machine::BootstrapClassMap, and resolveArrayClass expected to find the
primitive array classes there.  The fix is to check the
Machine::BootLoader map if we can't find it in
Machine::BootstrapClassMap.
2011-01-17 09:36:03 -07:00
Joel Dice
43cbfd3f3a support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding.  On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.

On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything.  We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.

So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers.  However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack.  This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.

One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.

Instead, this commit removes the need for a frame pointer.  Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time.  This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.

So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken.  More to come.
2011-01-16 19:05:05 -07:00
Joel Dice
afabe8e07e rework VM exception handling; throw OOMEs when appropriate
This rather large commit modifies the VM to use non-local returns to
throw exceptions instead of simply setting Thread::exception and
returning frame-by-frame as it used to.  This has several benefits:

 * Functions no longer need to check Thread::exception after each call
   which might throw an exception (which would be especially tedious
   and error-prone now that any function which allocates objects
   directly or indirectly might throw an OutOfMemoryError)

 * There's no need to audit the code for calls to functions which
   previously did not throw exceptions but later do

 * Performance should be improved slightly due to both the reduced
   need for conditionals and because undwinding now occurs in a single
   jump instead of a series of returns

The main disadvantages are:

 * Slightly higher overhead for entering and leaving the VM via the
   JNI and JDK methods

 * Non-local returns can make the code harder to read

 * We must be careful to register destructors for stack-allocated
   resources with the Thread so they can be called prior to a
   non-local return

The non-local return implementation is similar to setjmp/longjmp,
except it uses continuation-passing style to avoid the need for
cooperation from the C/C++ compiler.  Native C++ exceptions would have
also been an option, but that would introduce a dependence on
libstdc++, which we're trying to avoid for portability reasons.

Finally, this commit ensures that the VM throws an OutOfMemoryError
instead of aborting when it reaches its memory ceiling.  Currently, we
treat the ceiling as a soft limit and temporarily exceed it as
necessary to allow garbage collection and certain internal allocations
to succeed, but refuse to allocate any Java objects until the heap
size drops back below the ceiling.
2010-12-27 15:55:23 -07:00
Joel Dice
2e86f0ac57 fix race condition leading to deadlock on exit
There is a delay between when we tell the OS to start a thread and
when it actually starts, and during that time a thread might
mistakenly think it was the last to exit, try to shut down the VM, and
then block in joinAll when it finds it wasn't the last one after all.

The solution is to increment Machine::liveCount and add the new thread
to the process tree before starting it -- all while holding
Machine::stateLock for atomicity.  This helps guarantee that when
liveCount is one, we can be sure there's really only one thread
running or staged to run.
2010-12-20 19:00:23 -07:00
Joel Dice
5d5a18c482 set Thread::exception to null before creating ExceptionInInitializerError
If we don't do this, the VM will crash when it tries to create a stack
trace for the error because makeObjectArray will return null
immediately when it sees there is a pending exception.
2010-12-20 16:49:45 -07:00
Joel Dice
651ad20fc3 fix GC safety bugs 2010-12-09 22:17:57 -07:00
Joel Dice
3d49173b0b avoid inifinite recursion if java.lang.Object is missing; refactoring
When trying to create an array class, we try to resolve
java.lang.Object so we can use its vtable in the array class.
However, if Object is missing, we'll try to create and throw a
ClassNotFoundException, which requires creating an array to store the
stack trace, which requires creating an array class, which requires
resolving Object, etc..  This commit short-circuits this process by
telling resolveClass not to create and throw an exception if it can't
find Object.

While doing the above work, I noticed that the implementations of
Classpath::makeThrowable in classpath-avian.cpp and
classpath-openjdk.cpp were identical, so I made makeThrowable a
top-level function.

Finally, I discovered that Thread.setDaemon can only be called before
the target thread has been started, which allowed me to simplify the
code to track daemon threads in the VM.
2010-12-09 19:38:12 -07:00
Joel Dice
a5742f5985 update copyright years 2010-12-05 20:21:09 -07:00
Joel Dice
84520cde51 Merge remote branch 'origin/master' into openjdk 2010-12-01 14:40:58 -07:00
Joel Dice
4b1b3e032b add new array classes to classloader map upon creation
We were already doing this for non-array classes; we need to do it for
all classes or else risk creating duplicates.
2010-11-30 20:27:36 -07:00
Joel Dice
70a36c05b9 fix time==0 case in Unsafe.park and implement JVM_DumpThreads
Also, set name field on system threads for OpenJDK build to avoid NPEs
in Thread.getName.
2010-11-27 16:27:30 -07:00
Joel Dice
adc5c95214 fix GC safety bug in resolveClass 2010-11-27 14:44:49 -07:00
Joel Dice
e68dfe1e89 various fixes to get Eclipse 3.6 working
* add libnet.so and libnio.so to built-in libraries for openjdk-src build

 * implement sun.misc.Unsafe.park/unpark

 * implement JVM_SetClassSigners/JVM_GetClassSigners

 * etc.
2010-11-27 11:25:02 -07:00
Joel Dice
459f4d5194 fix openjdk-src bootimage build
The main change here is to use a lazily-populated vector to associate
runtime data with classes instead of referencing them directly from
the class which requires updating immutable references in the heap
image.  The other changes employ other strategies to avoid trying to
update immutable references.
2010-11-26 12:41:31 -07:00
Joel Dice
19dbc61e9f for heapdump=true builds, optionally generate dump on OOM
If the VM runs out of heap space and the "avian.heap.dump" system
property was specified at startup, the VM will write a heap dump to
the filename indicated by that property.  This dump may be analyzed
using e.g. DumpStats.java.
2010-11-18 10:55:00 -07:00
Joel Dice
aea02e545f fix race condition in interrupting/joining threads as they are exiting
My recent commit to ensure that OS resources are released immediately
upon thread exit introduced a race condition where interrupting or
joining a thread as it exited could lead to attempts to use
already-released resources.  This commit adds locking to avoid the
race.
2010-11-16 10:50:19 -07:00
Joel Dice
a611ccda6f Merge remote branch 'origin/master' into openjdk
Conflicts:
	makefile
	src/compile.cpp
	src/compiler.cpp
	src/type-generator.cpp
2010-11-16 10:18:08 -07:00
Joel Dice
64601e6f3e name VM-internal classes for heapdump=true builds
This makes heap dumps more useful since these classes are now refered
to by name instead of number.

This commit also adds a couple of utilities for parsing heap dumps:
PrintDump and DumpStats.
2010-11-16 09:31:49 -07:00
Joel Dice
f64d6c857b clean up OS resources immediately upon thread exit
Previously, we waited until the next GC to do this, but that can be
too long for workloads which create a lot of short-lived threads but
don't do much allocation.
2010-11-09 15:46:16 -07:00
Joel Dice
d0a6096eb0 add support for accessing embedded JARs as if they were directories
This allows OpenJDK to access time zone data which is normally found
under java.home, but which we must embed in the executable itself to
create a self-contained build.  The VM intercepts various file
operations, looking for paths which start with a prefix specified by
the avian.embed.prefix property and redirecting those operations to an
embedded JAR.

For example, if avian.embed.prefix is "/avian-embedded", and code
calls File.exists() with a path of
"/avian-embedded/javahomeJar/foo.txt", the VM looks for a function
named javahomeJar via dlsym, calls the function to find the memory
region containing the embeded JAR, and finally consults the JAR to see
if the file "foo.txt" exists.
2010-11-05 13:18:28 -06:00
Joel Dice
cabad6926f enable standalone OpenJDK builds
As described in readme.txt, a standalone OpenJDK build embeds all
libraries, classes, and other files needed at runtime in the resulting
binary, eliminating dependencies on external resources.
2010-11-04 11:02:09 -06:00
Joel Dice
25ca40931d keep track of original class in resolveField so we can throw an exception with a useful message 2010-10-24 11:49:59 -06:00
Joel Dice
1d4b54a9f6 fix failure to add abstract virtuals to class with no declared virtuals 2010-09-25 16:35:18 -06:00
Joel Dice
268d2de175 cache array class lookups in element class; misc. bugfixes 2010-09-25 15:54:01 -06:00
Joel Dice
89f6adc93c fix various classloading deadlocks and races 2010-09-22 13:58:46 -06:00
Joel Dice
17f495eb27 rework OpenJDK build to derive classpath and library path from environment
We now consult the JAVA_HOME environment variable to determine where
to find the system library JARs and SOs.  Ultimately, we'll want to
support self-contained build, but this allows Avian to behave like a
conventional libjvm.so.
2010-09-20 17:31:23 -06:00
Joel Dice
d0d53e2e10 fix custom-classloader-related concurrency problems and other bugs
The main changes in this commit ensure that we don't hold the global
class lock when doing class resolution using application-defined
classloaders.  Such classloaders may do their own locking (in fact,
it's almost certain), making deadlock likely when mixed with VM-level
locking in various orders.

Other changes include a fix to avoid overflow when waiting for
extremely long intervals and a GC root stack mapping bug.
2010-09-16 20:49:02 -06:00
Joel Dice
f485016637 implement more JVM_* methods and avoid duplicate array class loading 2010-09-14 18:52:57 -06:00
Joel Dice
d819a75f36 more work towards OpenJDK classpath support
The biggest change in this commit is to split the system classloader
into two: one for boot classes (e.g. java.lang.*) and another for
application classes.  This is necessary to make OpenJDK's security
checks happy.

The rest of the changes include bugfixes and additional JVM method
implementations in classpath-openjdk.cpp.
2010-09-14 10:49:41 -06:00
Joel Dice
cddea7187d preliminary support for using OpenJDK's class library
Whereas the GNU Classpath port used the strategy of patching Classpath
with core classes from Avian so as to minimize changes to the VM, this
port uses the opposite strategy: abstract and isolate
classpath-specific features in the VM similar to how we abstract away
platform-specific features in system.h.  This allows us to use an
unmodified copy of OpenJDK's class library, including its core classes
and augmented by a few VM-specific classes in the "avian" package.
2010-09-10 15:05:29 -06:00
Joel Dice
17c1a552d5 break each Class, Field, and Method into separate classes
In order to facilitate making the VM compatible with multiple class
libraries, it's useful to separate the VM-specific representation of
these classes from the library implementations.  This commit
introduces VMClass, VMField, and VMMethod for that purpose.
2010-09-01 10:13:52 -06:00
Joel Dice
fca98df55b fix process=interpret class initialization regression
A long time ago, I refactored the class initialization code in the VM,
but did not notice until today that it had caused the
process=interpret build to break on certain recursive initializations.
In particular, we were not always detecting when a thread recursively
tried to initialize a class it was already in the process of
initializing, leading to the mistaken assumption that another thread
was initializing it and that we should wait until it was done, in
which case we would wait forever.

This commit ensures that we always detect recursive initialization and
short-circuit it.
2010-08-04 18:27:54 -06:00
Joel Dice
3018290238 pre-allocate Thread::backupHeap for signal safety
It's not safe to use malloc from a signal handler, so we can't
allocate new memory when handling segfaults or Thread.getStackTrace
signals.  Instead, we allocate a fixed-size backup heap for each
thread ahead of time and use it if there's no space left in the normal
heap pool.  In the rare case that the backup heap isn't large enough,
we fall back to using a preallocated exception without a stack trace
as a last resort.
2010-06-19 16:40:21 -06:00
JET
c666ab58e3 Improved (should now be complete) Unicode support (UTF-8 for *nix and UTF-16 for Windows). 2010-04-20 10:03:07 -06:00
Joel Dice
c9b9db1621 reimplement Java object monitors (second try)
See commit 8120bee4dc for the original
problem description and solution.  That commit and a couple of related
ones had to be reverted when we found they had introduced GC-safety
regressions leading to crashes.

This commit restores the reverted code and fixes the regressions.
2010-02-04 17:56:21 -07:00
Joel Dice
48834be209 revert recent commits to reimplement Java object monitors
We're seeing race conditions which occasionally lead to assertion
failures and thus crashes, so I'm reverting these changes for now:

29309fb414
e92674cb73
8120bee4dc
2010-02-04 08:18:39 -07:00
Joel Dice
8120bee4dc reimplement Java object monitors to avoid running out of OS handles
Due to SWT's nasty habit of creating a new object monitor for every
task added to Display.asyncExec, we've found that, on Windows at
least, we tend to run out of OS handles due to the large number of
mutexes we create between garbage collections.

One way to address this might be to trigger a GC when either the
number of monitors created since the last GC exceeds a certain number
or when the total number of monitors in the VM reaches a certain
number.  Both of these risk hurting performance, especially if they
force major collections which would otherwise be infrequent.  Also,
it's hard to know what the values of such thresholds should be on a
given system.

Instead, we reimplement Java monitors using atomic compare-and-swap
(CAS) and thread-specific native locks for blocking in the case of
contention.  This way, we can create an arbitrary number of monitors
without creating any new native locks.  The total number of native
locks needed by the VM is bounded instead by the number of live
threads plus a small constant.

Note that if we ever add support for an architecture which does not
support CAS, we'll need to provide a fallback monitor implementation.
2010-02-01 18:40:47 -07:00
Joel Dice
805d1d13d8 mark system classloader initialized when using GNU Classpath to avoid security exceptions; only look for field in interfaces after looking in class and superclasses 2009-12-24 17:57:07 -07:00
Joel Dice
f588a62ae3 fix Classpath 0.98 compatibility issues 2009-12-22 21:34:04 -07:00
Joel Dice
2b4361c060 fix GNU Classpath build 2009-12-05 19:40:46 -07:00
Joel Dice
851187f0ce refine memory barrier implementation and usage 2009-11-30 15:38:16 +00:00
Joel Dice
0b09c6aa30 avoid busy wait when entering "exclusive" state 2009-11-29 16:53:05 -07:00
Joel Dice
6d9e1270ca fix race conditions in atomic operations 2009-11-29 09:08:07 -07:00
Joel Dice
1558b85acf second attempt to fix "idle to active" fast path
If another thread succeeds in entering the "exclusive" state while we
use the fast path to transition the current thread to "active", we
must switch back to "idle" temporarily to allow the exclusive thread a
chance to continue, and then retry the transition to "active" via the
slow path.
2009-11-28 15:35:15 -07:00
Joel Dice
3418a8bcbe fix race condition introduced in previous commit 2009-11-28 15:24:02 -07:00
Joel Dice
75934c8342 provide fast paths for common thread state transitions
These paths reduce contention among threads by using atomic operations
and memory barriers instead of mutexes where possible.  This is
especially important for JNI calls, since each such call involves two
state transitions: from "active" to "idle" and back.
2009-11-28 15:01:54 -07:00
Joel Dice
1a63b72b41 clean up float-vs.-int tracking in constant pools 2009-10-17 20:11:03 -06:00
Joel Dice
325f93b4d1 Merge branch 'master' into wip
Conflicts:

	src/compile.cpp
	src/compiler.cpp
	src/machine.h
	src/x86.cpp
2009-09-20 15:43:32 -06:00
Joel Dice
953cb69e5e move proxy and annotation code from C++ to Java
This allows code shrinkers to remove it if it's not used by the application.
2009-09-19 16:21:15 -06:00
Joel Dice
1a2eb3836c Merge branch 'master' of oss.readytalk.com:/var/local/git/avian 2009-09-18 18:01:57 -06:00
Joel Dice
7aa906d97b support runtime-visible annotations and java.lang.reflect.Proxy 2009-09-18 18:01:54 -06:00
Joel Dice
d0f8889e27 fix GC safety bugs in parseMethodTable and makeArrayClass 2009-09-18 12:20:35 -06:00
Joel Dice
b645c284b5 fix memory leak in debug build 2009-09-17 21:36:52 -06:00
Joel Dice
fcc4ff93e0 remove debug logging 2009-09-17 21:22:47 -06:00
Joel Dice
6519047342 fix bootimage build 2009-09-03 09:06:04 -06:00
Joel Dice
84ac2e417d follow reference pointer before using in in refrenceTargetUnreachable in case it points to a moved object 2009-09-01 18:32:21 -06:00
Joel Dice
4f794f533e fix handling of reachable, moved weak references in postVisit 2009-09-01 17:23:30 -06:00
Joel Dice
73dc058c14 implement StackTraceElement.getFileName properly 2009-08-27 16:28:44 -06:00
Joel Dice
1a0eef7e2d add support for building with MSVC on Windows 2009-08-26 18:26:44 -06:00
Joel Dice
4297fa04b3 run java finalizers in a separate thread to guarantee no application locks are held when doing so 2009-08-24 17:51:31 -06:00
Joel Dice
a56c1d8765 fix GC-safety bug in resolveSpec 2009-08-20 12:37:03 -06:00
Joel Dice
6196f61938 clear Thread::javaThread before entering zombie state, since clearing it in Thread::dispose is too late - the reference may already be invalid since we don't visit GC roots for zombie threads 2009-08-20 08:49:01 -06:00
Joel Dice
c4b5ecec90 implement Runtime.addShutdownHook and Thread.setDaemon; avoid segfaults due to an application calling e.g. CallStaticBooleanMethod when it really meant CallStaticVoidMethod 2009-08-19 14:27:03 -06:00
Joel Dice
01dcb1661b don't resolve all constant pool entries in linkClass - just the field and method specs 2009-08-18 15:27:21 -06:00
Joel Dice
c4edabdc02 implement ClassLoader.resolveClass and ensure class is linked in e.g. Class.getMethods; minor bugfixes 2009-08-18 14:26:28 -06:00
Joel Dice
7fcbf9d85c fix reading 2-byte UTF-8 constants 2009-08-14 08:52:31 -06:00
Joel Dice
3facd3f735 treat SoftReferences as WeakReferences; do vtable or interface table lookups as necessary in MyProcessor::invoke; various bugfixes 2009-08-13 09:17:05 -06:00
Joel Dice
db58097165 re-enable finalization 2009-08-11 10:04:41 -06:00
Joel Dice
fb5b0570c3 replace slashes with dots in class name before passing it to ClassLoader.loadClass 2009-08-11 09:20:49 -06:00
Joel Dice
28b5c46a0b fix GC safety bug in makeNewGeneral 2009-08-10 17:35:44 -06:00
Josh warner
1d3ef1fc43 Merge branch 'master' of git://oss.readytalk.com/avian, fixed problems that occured in broader testing
Conflicts:
	src/compile.cpp
	src/compiler.cpp
	src/powerpc.cpp
	src/x86.S
	src/x86.cpp
2009-08-10 13:20:23 -06:00
Joel Dice
001000364d add classloader parameter to functions which may directly or indirectly load classes; include methods inherited from interfaces (but not explicitly declared) in method tables and virtual tables of abstract classes 2009-08-10 07:56:16 -06:00
Joel Dice
d5f4811b43 check for exception after calling resolveClass in parseInterfaceTable 2009-08-04 08:50:04 -06:00
Joel Dice
f8bf83bfec fix recent regression in findInHierarchy 2009-08-04 08:42:16 -06:00
Joel Dice
cb563f76e1 check superinterfaces when looking up methods and fields 2009-08-03 16:16:41 -06:00
Joel Dice
ad0592df6f print class name properly when throwing NoSuchMethodError 2009-07-29 10:32:16 -06:00
Joel Dice
7b183e8f4e don't run Java finalizers when exiting the VM 2009-07-28 16:58:01 -06:00
Joel Dice
27d863790c Merge branch 'win64' into gnu
Conflicts:

	makefile
	src/compile-x86.S
	src/x86.S
	src/x86.cpp
2009-07-25 20:48:36 -06:00
Joel Dice
3787985b25 implement basic finalization support
This implementation does not conform to the Java standard in that
finalize methods are called from whichever thread happens to be garbage
collecting, and that thread may hold locks, whereas the standard
guarantees that finalize will be run from a thread which holds no locks.
Also, an object will never be finalized more than once, even if its
finalize method "rescues" (i.e. makes reachable) the object such that it
might become unreachable a second time and thus a candidate for
finalization once more.  It's not clear to me from the standard if this
is OK or not.

Nonwithstanding the above, this implementation is useful for "normal"
finalize methods which simply release resources associated with an
object.
2009-07-21 18:57:55 -06:00
Joel Dice
514d0bf7e5 fix deadlocks and other misbehaviors in class initialization code 2009-07-20 14:12:38 -06:00
Joel Dice
138f8444df Merge branch 'master' into gnu 2009-07-20 08:27:33 -06:00
Joel Dice
8662361f71 Merge branch 'master' of oss.readytalk.com:/var/local/git/avian 2009-07-20 08:27:17 -06:00
Joel Dice
47ab980550 fix thread heap overflow corner case in allocate3
The previous code relied on the invalid assumption that the thread-local
heaps for all threads would have been cleared immediately following a
garbage collection.  However, the last thing the garbage collection
function does is run finalizers which may allocate new objects.  This
can lead allocate3 to call allocateSmall with a size which is too large
to accomodate, overflowing the heap.

The solution is to iterate until there really is enough room for the
original allocation request.
2009-07-17 19:37:46 -06:00
Joel Dice
3e4336eba4 rearrange finalization code in collect to avoid inifinite recursion when finalizer allocates memory 2009-07-17 09:29:24 -06:00
Joel Dice
9c9eb86b2f fix deadlock in allocate3 when another thread wants to enter the exclusive state 2009-07-16 11:51:35 -06:00
Josh warner
9681a8a1ff added debugging method 'vmAddressFromLine' 2009-06-11 09:44:37 -06:00
Joel Dice
f239424930 implement NewDirectByteBuffer etc. properly when building against Classpath; call JNI_OnLoad if found in newly-loaded libraries 2009-06-10 18:15:00 -06:00
Joel Dice
c1ca653fef intern CONSTANT_Utf8 pool entries to save memory and reduce bootimage size 2009-06-06 18:26:23 -06:00
Joel Dice
ac34bc072c remove obsolete todo comments 2009-06-06 14:58:06 -06:00
Joel Dice
0857f53651 more progress on GNU Classpath compatibility 2009-06-04 17:21:42 -06:00
Joel Dice
98be5c509e more progress towards GNU Classpath compatibility 2009-06-03 16:17:55 -06:00
Joel Dice
ba5105c374 throw NoSuchMethodError in resolveMethod if method not found 2009-06-02 18:55:12 -06:00