Commit Graph

1479 Commits

Author SHA1 Message Date
Joel Dice
bf8eb52611 reduce CodeCapacity value to 16MB in bootimage.cpp
32MB was just slightly too large for PowerPC immediate call instructions
to span, and 16MB matches the JIT executable memory area we use in
compile.cpp.
2010-06-25 21:54:01 -06:00
Joel Dice
6d887ef34f comment-out debug logging in powerpc.cpp 2010-06-25 21:51:32 -06:00
Joel Dice
d308ba93c7 fix tails=true bootimage=true build
compileDirectInvoke does some magic to optimize tail calls to native
methods which involves storing the return address (which we'll never
actually return to, since it's a tail call) in a thread-local field so
the thunk function can figure out which native method to look up at
runtime.  Since this address will change when the boot image is
loaded, the boot image creation code needs to know about it.
2010-06-25 21:13:59 -06:00
Joel Dice
98b82a9bc1 fix callContinuation regression
callContinuation failed to call the correct continuation when feeding
it an exception due to a regression introduced with the
Thread.getStackTrace changes.
2010-06-25 09:51:35 -06:00
Joel Dice
74930d75e7 update PowerPC assembly Thread field offsets
The new Thread::defaultHeap declaration has increased the offset of all
the fields following it.

This commit also makes vmInvoke_returnAddress global so it can be refered
to from compile.cpp.
2010-06-24 19:35:07 -06:00
Joel Dice
2d6a179bf2 update assembly code field offsets to reflect new Thread field declaration
Thread::defaultHeap is now an inline array, which means the offsets of
all the fields following have increased.
2010-06-24 19:12:15 -06:00
Joel Dice
3e304521d0 initialize MyProcessor::callTableSize in constructor
This field was being used uninitialized, which could lead to an out of
memory condition when we tried to grow the call table to a ridiculous
size.
2010-06-24 19:09:50 -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
Joel Dice
7ea6036842 fix isThunkUnsafeStack
This function was broken in two different ways:

 1. It only checked MyProcessor::thunks, not MyProcessor::bootThunks.
    It needs to check both.

 2. When checking MyProcessor::thunks, it used fields from
    MyProcessor::bootThunks instead of from the same thunk collection.

This fixes both problems.
2010-06-16 20:29:41 -06:00
Joel Dice
ea797fd03c fix windows build 2010-06-16 18:37:22 -06:00
Joel Dice
39a82a4006 update bootimage.cpp to reflect BootImage restructuring 2010-06-15 19:49:48 -06:00
Joel Dice
18d1c54956 fix typo in compile-x86.S 2010-06-15 19:47:06 -06:00
Joel Dice
9559aca825 fix Thread.getStackTrace race conditions
Implementing Thread.getStackTrace is tricky.  A thread may interrupt
another thread at any time to grab a stack trace, including while the
latter is executing Java code, JNI code, helper thunks, VM code, or
while transitioning between any of these.

To create a stack trace we use several context fields associated with
the target thread, including snapshots of the instruction pointer,
stack pointer, and frame pointer.  These fields must be current,
accurate, and consistent with each other in order to get a reliable
trace.  Otherwise, we risk crashing the VM by trying to walk garbage
stack frames or by misinterpreting the size and/or content of
legitimate frames.

This commit addresses sensitive transition points such as entering the
helper thunks which bridge the transitions from Java to native code
(where we must save the stack and frame registers for use from native
code) and stack unwinding (where we must atomically update the thread
context fields to indicate which frame we are unwinding to).  When
grabbing a trace for another thread, we determine what kind of code we
caught the thread executing in and use that information to choose the
thread context values with which to begin the trace.  See
MyProcessor::getStackTrace::Visitor::visit for details.

In order to atomically update the thread context fields, we do the
following:

 1. Create a temporary "transition" object to serve as a staging area
    and populate it with the new field values.

 2. Update a transition pointer in the thread object to point to the
    object created above.  As long as this pointer is non-null,
    interrupting threads will use the context values in the staging
    object instead of those in the thread object.

 3. Update the fields in the thread object.

 4. Clear the transition pointer in the thread object.

We use a memory barrier between each of these steps to ensure they are
made visible to other threads in program order.  See
MyThread::doTransition for details.
2010-06-15 19:10:48 -06:00
Joel Dice
a31ae24005 Merge branch 'wip' 2010-05-03 16:32:40 -06:00
Eric Scharff
9909c0cec3 Fix Mac OS X specific path bug
In Mac OS X, if a path contains a space, the path of the main executable
will contain a special URL-encoded character (%20 in this case).  This
probably happens when any non-ASCII character is provided.

The fix is to use CFURLCreateStringByReplacingPercentEscapes which
creates a path that the POSIX API likes better.
2010-04-26 10:24:53 -06:00
JET
3aac50555b fixed ARM interpreted-mode regression 2010-04-20 15:51:35 -06:00
JET
1ea2a3a6dc Merge branch 'wip' of oss.readytalk.com:/var/local/git/avian into wip 2010-04-20 10:04:47 -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
e5fad03632 fix MSVC build rot 2010-04-15 11:11:10 -06:00
JET
34f51114a1 Merge branch 'master' into wip 2010-04-14 09:27:24 -06:00
JET
b2f5e71d22 ARM and UTF-8 work 2010-04-14 09:26:50 -06:00
Joel Dice
03ec9e6f19 Merge branch 'master' into wip 2010-04-14 09:22:42 -06:00
Joel Dice
3e5b2cbc7b fix miscompilation of 64-bit volatile field reads and writes on x86_32
We were generating code which clobbered the data we were putting into
64-bit volatile fields (and potentially also clobbering the target or
source object in the case of non-static fields) due to misplaced
synchronization code.  Reordering this code ensures that both the data
and the target or source survive across calls to synchronization
helper functions.
2010-03-01 18:24:25 -07:00
Joel Dice
c2a9424f91 implement compileTimeMemoryBarrier in arch.h
This has the same implementation as programOrderMemoryBarrier in
x86.h, but makes it available on all architectures.
2010-02-04 18:30:13 -07:00
Joel Dice
99bb7924b0 fix stack frame mapping code for exception handlers
Previously, the stack frame mapping code (responsible for statically
calculating the map of GC roots for a method's stack frame during JIT
compilation) would assume that the map of GC roots on entry to an
exception handler is the same as on entry to the "try" block which the
handler is attached to.  Technically, this is true, but the algorithm
we use does not consider whether a local variable is still "live"
(i.e. will be read later) when calculating the map - only whether we
can expect to find a reference there via normal (non-exceptional)
control flow.  This can backfire if, within a "try" block, the stack
location which held an object reference on entry to the block gets
overwritten with a non-reference (i.e. a primitive).  If an exception
is later thrown from such a block, we might end up trying to treat
that non-reference as a reference during GC, which will crash the VM.

The ideal way to fix this is to calculate the true interval for which
each value is live and use that to produce the stack frame maps.  This
would provide the added benefit of ensuring that the garbage collector
does not visit references which, although still present on the stack,
will not be used again.

However, this commit uses the less invasive strategy of ANDing
together the root maps at each GC point within a "try" block and using
the result as the map on entry to the corresponding exception
handler(s).  This should give us safe, if not optimal, results.  Later
on, we can refine it as described above.
2010-02-04 18:03:32 -07: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
29309fb414 update Thread field offsets to reflect recent additions
Every time we add or remove fields to Thread, we need to update the
assembly code to reflect the new offsets.
2010-02-02 12:26:09 -07:00
Joel Dice
e92674cb73 fix race condition in monitorWait
We don't want to check Thread::waiting until we have re-acquired the
monitor, since another thread might notify us between releasing
Thread::lock and acquiring the monitor.
2010-02-02 12:24:05 -07:00
Joel Dice
3bc37d6e2a fix encoding of single byte register-to-memory moves on x86_64
We need to prefix instructions of the form "mov R,M" with a REX byte
when R is %spl, %bpl, %sil, or %dil.  Such moves are unencodable on
32-bit x86, and, because of the order in which we pick registers,
pretty rare on 64-bit systems, which is why this took so long to
notice.
2010-02-02 11:37:08 -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
45476eb591 fix handling of volatile longs and doubles on PowerPC
We were miscompiling methods which contained getfield, getstatic,
putfield, or putstatic instructions for volatile 64-bit primitives on
32-bit PowerPC due to not noticing that values in registers are clobbered
across function calls.

The solution is to create a separate Compiler::Operand instance for each
object monitor reference before and after the function call to avoid
confusing the compiler.  To avoid duplicate entries in the constant pool,
we add code look for and, if found, reuse any existing entry for the same
constant.
2010-01-27 17:46:04 -07:00
jet
ea4b4bfcbf Merge branch 'wip' of oss.readytalk.com:/var/local/git/avian into wip 2010-01-06 10:57:55 -07:00
Joel Dice
3686d2131d fix jsr/ret code generation bug
We were generating code to marshal values into place prior to a jump,
but placing it after the jump instruction, which made it useless.
2010-01-04 17:17:16 -07:00
Joel Dice
20f92bbd05 specify java.home system property in GNU Classpath build
Currently, we just set this to /tmp (or the equivalent) since Avian
doesn't really have a home.  This avoids a NullPointerException from
javax/xml/parsers/SAXParserFactory.
2010-01-04 17:14:00 -07:00
jet
8c8020811a Merge branch 'wip' of oss.readytalk.com:/var/local/git/avian into wip 2009-12-28 11:14:26 -07:00
Joel Dice
664cb3cd39 don't try to parse annotation tables more than once; use defining classloader when loading array classes during linking 2009-12-24 17:58:48 -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
40c65f66bf add (commented-out) debug logging to gnu.cpp 2009-12-24 17:54:02 -07:00
Joel Dice
7b2322e7f7 accept any source site in resolveTargetSites, whether it matches the next read or not 2009-12-24 17:47:58 -07:00
jet
77990b9489 Merge branch 'wip' of oss.readytalk.com:/var/local/git/avian into wip 2009-12-23 09:26:17 -07:00
Joel Dice
f588a62ae3 fix Classpath 0.98 compatibility issues 2009-12-22 21:34:04 -07:00
Joel Dice
30db38ebd6 replace calls to ExceptionOccurred with calls to ExceptionCheck
The latter is cheaper (avoids a state transition and possible memory
allocation) when we just want to know if an exception is thrown
without needing a handle to that exception.
2009-12-16 19:25:03 -07:00
Joel Dice
4c0ede8b9a reuse JNI references when possible
Before allocating a new reference in NewGlobalReference or when
creating a local reference, we look for a previously-allocated
reference pointing to the same object.  This is a linear search, but
usually the number of elements in the reference list is small, whereas
the memory, locking, and allocation overhead of creating duplicate
references can be large.
2009-12-16 19:16:51 -07:00
Joel Dice
7cf25a0fc3 fix process=interpret build 2009-12-14 18:01:28 -07:00
Joel Dice
d5f5c2351b use _ReadWriteBarrier intrinsic for MSVC build 2009-12-12 18:50:59 -07:00
Joel Dice
2b4361c060 fix GNU Classpath build 2009-12-05 19:40:46 -07:00
Joel Dice
b6ac05ba9d remove unecessary code from resolveSourceSites and resolveTargetSites 2009-12-05 15:49:53 -07:00
jent
4cf9e16897 Merge branch 'master' of oss.readytalk.com:/var/local/git/avian 2009-12-04 12:02:06 -07:00
jent
99a1c12682 Files to add Deflater and DeflaterOutputStream to java.util.zip for
avian
2009-12-04 12:01:31 -07:00