Commit Graph

524 Commits

Author SHA1 Message Date
Joel Dice
e8e3c9066f implement sun.misc.Unsafe raw memory access methods
The primitive get/put methods are implemented as intrinsics by the
compiler for performance.
2012-03-06 13:07:59 -07:00
Joel Dice
5203cb5dcf implement JNI methods NewWeakGlobalRef and DeleteWeakGlobalRef 2012-02-29 11:51:30 -07:00
Joel Dice
5a5d2a8dd2 fix JNI float argument passing
Floats are implicitly promoted to doubles when passed as part of a
variable-length argument list, so we can't treat them the same way as
32-bit integers.
2012-02-28 15:35:28 -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
8501ce8711 avoid using runtime-generated thunks for bootimage native methods 2011-10-03 08:05:49 -06:00
Joel Dice
db9f9a300d Revert "remove distinction between thunks and bootThunks in compile.cpp"
This reverts commit 88d614eb25.

It turns out we still need separate sets of thunks for AOT-compiled
and JIT-compiled code to ensure we can always generate efficient jumps
and calls to thunks on architectures such as ARM and PowerPC, whose
relative jumps and calls have limited ranges.
2011-10-01 18:11:02 -06:00
Joel Dice
b063f10ad5 fix Windows build 2011-09-30 14:44:25 -06:00
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