Commit Graph

517 Commits

Author SHA1 Message Date
Joel Dice
88d614eb25 remove distinction between thunks and bootThunks in compile.cpp
Now that the AOT-compiled code image is position-independent, there is
no further need for this distinction.  In fact, it was harmful,
because we were still using runtime-generated thunks when we should
have been using the ones in the code image.  This resulted in
EXC_BAD_ACCESS errors on non-jailbroken iOS devices.
2011-09-30 13:17:28 -06:00
Joel Dice
0372d999d3 use TargetBytesPerWord instead of BytesPerWord where appropriate 2011-09-23 23:25:52 -06:00
Joel Dice
3fa4a7001d fix x86->powerpc boot image cross build
This fixes the remaining cross-endian translation issues needed to
build powerpc boot images on x86.
2011-09-23 22:31:24 -06:00
Joel Dice
559af69269 various ARM fixes 2011-09-20 19:50:38 -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
349d381d95 progress towards cross-endian bootimage builds
This fixes a number of bugs concerning cross-architecture bootimage
builds involving diffent endianesses.  There will be more work to do
before it works.
2011-09-16 20:53:08 -06:00
Joel Dice
ab840c91db Merge branch 'oss-master' into ios 2011-09-12 20:27:59 -06:00
Joel Dice
be01e5b687 fix handling of 64-bit arguments to Method.invoke on 32-bit architectures
The previous code failed to account for alignment padding in the
Double and Long classes.
2011-09-12 20:26:32 -06:00
Joel Dice
84a6daa400 fix unused parameter warning 2011-09-01 11:36:00 -06:00
Joel Dice
e505cbe99d more progress towards cross-architecture bootimage builds
This commit fixes a lot of bugs.  All tests are now pass for Linux
x86_64 to Linux i386 cross builds.
2011-08-31 21:18:00 -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
3df3892d34 throw AbstractMethodError when appropriate in prepareMethodForCall
Otherwise, we'll crash later when we try to compile an abstract
method.
2011-08-12 14:19:21 -06:00
Joel Dice
c3824c6844 fix crash when encountering invokespecial call to abstract method
We must throw an AbstractMethodError when such a call is executed (not
when the call is compiled), so we compile this case as a call to a
thunk which throws such an error.
2011-07-17 19:54:55 -06:00
Joel Dice
a2933c1f9e update copyright years in compile.cpp 2011-07-16 19:08:39 -06:00
Joel Dice
3ec4ef9bd2 fix stack unwinding from native methods for tails=true build
We can't clear t->trace->targetMethod until after findUnwindTarget has
been called or we'll lose track of where we are on the stack.
2011-07-13 18:06:02 -06:00
Joel Dice
92adc83caf remove NPE debug logging 2011-05-29 11:16:52 -06:00
Joel Dice
7bea2b6b7d fix putstatic/putfield for 64-bit volatiles
We must call acquireMonitorForObject before popping the
putstatic/pushfield operands off the stack to avoid clobbering said
operands.
2011-05-23 12:38:12 -06:00
Joel Dice
7c30e44601 add appropriate memory barriers to double-checked locking code 2011-04-10 14:46:53 -06:00
Joel Dice
8091803b59 set MaxNativeCallFootprint to 5 on 32-bit systems
Thunks such as divideLong now take a pointer and two int64_t
arguments, which amounts to 5 words of stack space on a 32-bit system.
2011-04-10 12:55:42 -06:00
Joel Dice
3febd7cea7 load libfontmanager.so before trying to resolve FontManager.initIDs
sun.font.FontManager.initIDs is a native method defined in
libfontmanager.so, yet there seems to be no mechanism in OpenJDK's
class library to actually load that library, so we lazily load it
before trying to resolve the method.
2011-04-10 11:26:44 -06:00
Joel Dice
239fd98781 fix compilation of unusual exception handlers
As described in commit 36aa0d6, apps such as jython which generate
bytecode dynamically can produce patterns of bytecode for which the
VM's compiler could not handle properly.  However, that commit
introduced a regression and had to be partially reverted.

It turns out the real problem was the call to Compiler::restoreState
which we made before checking whether we were actually ready to
compile the exception handler (we delay compiling an exception handler
until and unless the try/catch block it serves has been compiled so we
can calculate the stack maps properly).  That confused the compiler in
rare cases, so we now only call restoreState once we're actually ready
to compile the handler.
2011-04-09 12:44:28 -06:00
Joel Dice
97aec1691e fix jsr/ret stack mapping regression
My last commit introduced a regression in JIT compilation of
subroutines.  This reverts the specific change which caused the
regression.  Further work will be needed to address the case which
that change was intended to fix (namely, exception handlers which
apply to multiple try/catch blocks).
2011-04-08 20:15:36 -06:00
Joel Dice
36aa0d6792 improve handling of unusual bytecode in JIT compiler
Bytecode generated by compilers other than javac or ecj (such as
jython's dynamically generated classes) can contain unreachable code
and exception handlers which apply to more than one try/catch scope.
Previously, the VM's JIT compiler did not handle either of these cases
well, hence this commit.
2011-04-08 18:50:22 -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
d5ae053f11 handle invokevirtual calls to non-virtual methods
OpenJDK's sun.reflect.MethodAccessorGenerator can generate
invokevirtual calls to private methods (which we normally consider
non-virtual); we must compile them as non-virtual calls since they
aren't in the vtable.
2011-03-26 23:13:05 -06:00
Joel Dice
0f38673baa fix line number and exception handler scope regression
It turns out commit 31eb047 was too aggressive and led to incorrect
calculation of line numbers for machine addresses, as well as
potentially incorrect exception handler scope calculation.  This fixes
the regression.
2011-03-26 19:55:23 -06:00
Joel Dice
01b3f1cb93 fix GCC 4.6 unused variable warnings 2011-03-26 14:43:03 -06:00
Joel Dice
31eb047391 handle redundant, unreachable gotos in JIT compiler
I recently encountered a Batik JAR with a method containing a
redundant goto which confused the JIT compiler because it was refered
to in the exception handler and line number tables despite being
unreachable.  I don't know how such code was generated, but this
commit ensures the compiler can handle it.
2011-03-25 19:13:10 -06:00
Joel Dice
b9f8188544 don't try to release monitor if we get OOME when trying to acquire it
We can't blindly try release the monitors for all synchronized methods
when unwinding the stack since we may not have finished acquiring the
most recent one when the exception was thrown.
2011-03-25 18:40:51 -06:00
Joel Dice
86733a25f4 increase executable area size to 30MB
Big applications can exceed the 16MB limit we previously used.
Increasing this above 30MB (if/when desired) will require changes to
the ARM and PowerPC JIT code to work around immediate branch encoding
limits on those platforms,
2011-03-17 21:24:35 -06:00
Joel Dice
110e2e1d52 fix putstatic code order regression in compile.cpp
Also, ensure that class is initialized before getting or setting
static fields in lazy loading code.
2011-03-17 08:46:46 -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
255fc9f9d3 handle long conditional immediate branches properly on PowerPC
Due to encoding limitations, the immediate operand of conditional
branches can be no more than 32KB forward or backward.  Since the
JIT-compiled form of some methods can be larger than 32KB, and we also
do conditional jumps to code outside the current method in some cases,
we must work around this limitation.

The strategy of this commit is to provide inline, intermediate jump
tables where necessary.  A given conditional branch whose target is
too far for a direct jump will instead point to an unconditional
branch in the nearest jump table which points to the actual target.

Unconditional immediate branches are also limited on PowerPC, but this
limit is 32MB, which is not an impediment in practice.  If it does
become a problem, we'll need to encode such branches using multiple
instructions.
2011-02-27 23:03:13 -07:00
Joel Dice
a4c4d54cdd restore MyThread::ip in MyThread::CallTrace destructor
This is necessary to ensure we can unwind the stack properly on ARM
after returning from a recursive invocation of vmInvoke.
2011-02-25 11:04:23 -07:00
Joel Dice
e20daca297 use link register to determine return address when appropriate in getStackTrace
On PowerPC and ARM, we can't rely on the return address having already
been saved on the stack on entry to a thunk, so we must look for it in
the link register instead.
2011-02-21 15:25:52 -07:00
Joel Dice
20f4510122 fix ARM stack unwinding (part 2)
My previous attempt at this was incomplete; it did not address
Java->native->Java->native call sequences, nor did it address
continuations.  This commit takes care of both.
2011-02-20 13:49:40 -07:00
Joel Dice
8a88c6ee3c fix ARM stack unwinding
We can't rely on the C++ compiler to save the return address in a
known location on entry to each function we might call from Java
(although GCC 4.5 seems to do so consistently, which is why I hadn't
realized the unwinding code was relying on that assumption), so we
must store it explicitly in MyThread::ip in each thunk.  For PowerPC
and x86, we continue saving it on the stack as always, since the
calling convention guarantees its location relative to the stack
pointer.
2011-02-19 20:52:14 -07:00
Joel Dice
59183c7821 fix subroutine stack mapping bug leading to crashes during GC
The stack mapping code was broken for cases of stack slots being
reused to hold primitives or addresses within subroutines after
previously being used to hold object references.  We now bitwise "and"
the stack map upon return from the subroutine with the map as it
existed prior to calling the subroutine, which has the effect of
clearing map locations previously marked as GC roots where
appropriate.
2011-02-16 14:29:57 -07:00
Joel Dice
4d5aeb5ab2 disable debug logging in compile.cpp 2011-02-02 08:32:40 -07:00
Joel Dice
635f5ba7e6 avoid garbage collection from e.g. divideLong thunk
It is dangerous to initiate a GC from a thunk like divideLong (which
was possible when allocating a new ArithmeticException to signal
divide-by-zero) since we don't currently generate a GC root frame map
for the return address of the thunk call.  Instead, we use the backup
heap area if there is room, or else throw a pre-allocated exception
instead.
2011-01-31 21:18:55 -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
1186413be2 debug logging tweaks in compile.cpp 2011-01-29 11:11:27 -07:00
Joel Dice
f980ceb13e enable use-frame-pointer=true build
Also, include Continuations, Coroutines, and DynamicWind tests in test
suite for continuations=true build.
2011-01-27 21:06:01 -07:00
Joel Dice
b7157c802a fix continuations=true build 2011-01-27 11:54:41 -07:00
Joel Dice
c1a0d8b6fc more work on frame-pointer-less unwinding
This fixes the tails=true build (at least for x86_64) and eliminates
the need for a frame table in the tails=false build.  In the
tails=true build, we still need a frame table on x86(_64) to help
determine whether we've caught a thread executing code to do a tail
call or pop arguments off the stack.  However, I've not yet written
the code to actually use this table, and it is only needed to handle
asynchronous unwinds via Thread.getStackTrace.
2011-01-25 17:22:43 -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
306f1282d0 throw ArithmeticException on divide-by-zero 2010-12-19 17:47:21 -07:00
Joel Dice
d18240cbd6 check for stack overflow on entry to all non-leaf methods
We now check for stack overflow in the JIT build as well as the
interpreted build, throwing a StackOverflowError if the limit
(currently hard-coded to 64KB, but should be easy to make
configurable) is exceeded.
2010-12-19 15:23:19 -07:00