Commit Graph

341 Commits

Author SHA1 Message Date
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