Commit Graph

2767 Commits

Author SHA1 Message Date
Joel Dice
678d7debda fix bootimage build
We now detect both metafactory and altMetafactory lambdas when
bootimage-compiling invokedynamic instructions, as well as make
allowance for the same lambda being invoked by multiple invokedynamic
instructions (as is the case for Serializable lambdas).
2016-12-05 17:43:17 -07:00
Joel Dice
69426b9945 fix some lambda bugs
For lambdas that implement java.io.Serializable, the compiler emits
calls to LambdaMetaFactory.altMetafactory, not
LambdaMetaFactory.metafactory, so I've provided a stub implementation
that ignores that currently ignores the extra parameters it receives.

This also fixes a bug in compiling lambda glue code for lambdas that
take longs and/or doubles.
2016-12-04 21:06:07 -07:00
Joel Dice
a4d9037ae4 fix openjdk-src build with JDK 8 2016-12-04 19:02:30 -07:00
Joel Dice
8b469195de add missing Unsafe calls for recent JDK 7 updates 2016-11-06 19:16:11 -07:00
Joel Dice
650941cdf5 print informative message if lambda encountered with no host VM
Per a recent bug report in the hello-ios project, we found that
bootimage-generator would abort with no explanation if it encountered
a lambda invocation and the `-hostvm` option was unspecified.  This
commit ensures that a helpful message is printed before exiting.
2016-09-16 14:01:00 -06:00
Joshua Warner
95cd300bbd Don't access potentially mis-aligned, non-existent length field for non-array objects (fixes #486) 2016-05-26 14:37:26 +00:00
Joel Dice
aacbd7cc7a support Java 8 default interface methods 2016-05-14 13:32:42 -06:00
Joel Dice
a538f54033 add sun.misc.Unsafe.putDouble(Object,long,double) 2016-03-01 18:28:04 -07:00
Joel Dice
2bb3ea2532 do not null-terminate ZipEntry names in openjdk-src builds
OpenJDK's java.util.zip.ZipFile.getEntryBytes should return a byte
array that is not null-terminated, but we were giving it one that was
null-terminated, which caused lookups to fail later when
ZipFile.getInputStream was called.
2016-02-15 18:30:56 -07:00
Joel Dice
ba101699a7 fix bootimage regression 2016-01-16 10:20:10 -07:00
Joel Dice
b5308c4866 synchronize on Java class rather than VM class in static synchronized methods
Previously, the following code would throw an IllegalMonitorStateException:

public class Test {
  public static synchronized void main(String[] args) {
    Test.class.notify();
  }
}

The problem stems from the fact that for a long time Avian has had two
representations of a given class: avian.VMClass and java.lang.Class.
It used to be that there was only one, java.lang.Class, but that
didn't play nicely with OpenJDK's class library, so we split it into
two.  Unfortunately, we forgot to update the JIT and interpreter
accordingly, so a static synchronized method would acquire the
avian.VMClass instance, whereas Foo.class.notify() would be invoked on
the java.lang.Class instance.

This commit fixes it.
2016-01-16 08:34:30 -07:00
Joel Dice
80dc32094f fix openjdk/openjdk-src builds for latest JDKs 7 and 8
The tower of patches and hacks grows higher.  Ideally, we'll just drop
support for JDK 7 soon and clean this mess up a bit, but TravisCI
still hasn't gotten the memo that it's dead, so we muddle onward.

I've tested this on Windows, but not yet Linux or OS X.  Wanted to get
a PR before I move on to that.
2016-01-12 16:37:03 -08:00
Joel Dice
d5a5b5309a support AOT-compilation of Java 8 lambda expressions
These expressions are tricky because they rely on invokedynamic, which
normally implies runtime code generation.  However, since lambdas
don't actually use the "dynamicness" of invokedynamic, we can convert
them into static calls to synthetic classes at compile time.

Since I had already written code to synthesize such classes in Java
and I didn't want to rewrite it in C++, I needed to add support for
running Java code to the bootimage generator.  And since the primary
VM used by the generator is purpose-built to generate AOT-compiled
code for a specific target architecture and is not capable of
generating or running JIT-compiled code for the host architecture, I
added support for loading a second, independent, host-specific VM for
running Java code.

The rest of the patch handles the fact that each method compilation
might cause new, synthetic classes to be created, so we need to make
sure those classes and their methods are included in the final heap
and code images.  This required breaking some giant code blocks out of
makeCodeImage into their own methods, which makes the diff look
scarier than it really is.
2015-09-13 14:21:24 -06:00
Joel Dice
763aada4b0 optionally specify reentrancy when creating a System object
This allows multiple Avian VMs to share the same process space,
provided they don't try to use functionality that involves global
shared resources (e.g. signal handling).
2015-09-12 20:08:54 -06:00
Joel Dice
66712a8cff add invokedynamic support to interpreter 2015-08-06 17:22:14 -06:00
Joel Dice
8a7944d25c add support for openjdk=$JDK8_HOME
All tests pass for the process=compile build.  Next step: process=interpret.
2015-08-06 13:30:18 -06:00
Joel Dice
2465459079 implement basic Java 8 lambda support
The two big pieces here are basic invokedynamic support and a working
version of LambdaMetaFactory.metafactory.  The latter works by
dynamically building a synthetic class with three methods: a static
factory method, a constructor for the factory method to call, and a
method to satisfy the requested interface which defers to the
specified MethodHandle.

This work relies heavily on Avian's specific MethodType and
MethodHandle implementations, which provide extra, non-standard
features to make code generation easier.  That means we'll probably
need to use Avian's versions of java.lang.invoke.* even when building
with the OpenJDK or Android class libraries.
2015-08-06 13:30:18 -06:00
joshuawarner32@gmail.com
792684b935 first pass at minimal invokedynamic support for Java 8 lambdas
This is a bunch of commits squashed into one per Josh's request.

add dynamicTable field

add invokedynamic instruction

add defaultDynamic bootimage field

add dummy invokedynamic support in bootimage-generator

add defaultDynamic thunk

check dynamicTable offset

comment defaultDynamicThunk to fix unused function

comment defaultDynamicThunk to fix unused function

add dynamicTable / dynamicIndex stuff

comment dynamicIndex and dynamicTable

add invokedynamic instruction impl

stub out addDynamic

unstub addDynamic

don't allow tail calls in invokedynamic

implement stub JVM_GetTemporaryDirectory method

(build broken) begin add InvokeDynamicTest

Revert "(build broken) begin add InvokeDynamicTest"

This reverts commit 77f9c54e32ac66d0803eeab93e4a10d3541987a8.

add InternalError

add URLClassPath.c for openjdk-src builds

implement stub JVM_KnownToNotExist and JVM_GetResourceLookupCache methods

intercept open0 / open for openjdk

add basic java/lang/invoke stubs

remove non-public java/lang/invoke classes

fix invokedynamic example building

<wip debugging>
2015-08-06 13:30:05 -06:00
Joshua Warner
82fd3a8dcb fix #447: leak in compile.cpp (thanks, @mretallack!) 2015-08-06 13:28:47 -06:00
Joel Dice
630d9a165e fix GC crash for bootimage builds
In a bootimage=true build, we create allocate certain objects as
"immortal fixies", which means they will never been deallocated at
runtime and should only be visited if/when they point to objects which
might move during garbage collection.  However, there was a bug in the
following case:

 1. immortal fixie F is updated to point to a movable object M and
 thus F is added to the list of fixies to visit during the next minor
 collection (but not the next major one, since all reachable objects
 are visited during a major collection, and there's no point in
 visiting an unreachable object, whereas during a minor collection we
 have to visit F because we don't know if it's reachable or not)

 2. a major collection occurs, but F is not reachable and thus is not
 visited, whereas M is moved

 3. a minor collection occurs, and since F is still in the list, it is
 visited, but since it contains a stale pointer to M's old location,
 we crash

The solution is to ensure unreachable immortal fixies are removed from
the above list after each major collection, thus guaranteeing they
won't be visited on any subsequent collection.
2015-07-07 17:28:32 -06:00
Joshua Warner
ebd6bb2e6d Merge pull request #442 from dicej/master
fix GCC 5.1 compiler warnings/errors
2015-06-25 12:33:27 -07:00
Ilya Mizus
2c7e3960d6 llabs call fixed 2015-06-24 17:49:56 +03:00
Joel Dice
1aaef6ce88 fix GCC 5.1 compiler warnings/errors
GCC is a lot more sensitive about -Werror=unused-variable, to the
point that stuff declared in header files but unused in a given
compilation unit is flagged.  This may be due to the way we're
here's the fix.
2015-06-23 14:07:48 -06:00
Ilya Mizus
fe6f72d16e fixed abs() compilation for Android classpath on OSX 2015-06-23 16:04:42 +03:00
tarotanaka0
7e1debef44 fix JNI stack alignment 2015-06-04 16:02:29 +09:00
Joshua Warner
ba9b85f7c3 fix concurrency bugs on ios+arm64 in enter
At first, it might look like the atomicIncrement operations here,
since they resolve to OSAtomicCompareAndSwap32Barrier, ought to
provide all the memory barrier guarantees we need; however, it turns
out it's not quite sufficient.

Here's why: Apple's OSAtomic*Barrier operations guarantee that memory
operations *before* the atomic op won't be reordered with memory
operations *after* the atomic op - but makes no guarantee that the
atomic op itself won't be reordered with other operations before or
after it.  The key is that the atomic operation is not really atomic,
but rather consists of separate read, check and write steps - in a
loop, no less.  Here, presumably, the read of t->m->exclusive is
hoisted by the out-of-order processor to between the read and write
steps of the "atomic" increment of t->m->activeCount.

Longer term, it probably makes sense to replace this with the c11
<stdatomic.h> operations or the c++11 <atomic> types.  We ought to
actually use the atomic increment operations provided there.  As it
is, our atomicIncrement looks substantially less efficient than those,
since it's actually implemented on arm64 as two nested loops (one in
atomicIncrement and one in the compare-and-swap) instead of one.  We
should also evaluate whether the various instances of atomic
operations actually need as strong of barriers as we're giving them.

FWIW, the gcc __sync_* builtins seem to have the same problem, at
least on arm64.
2015-05-07 13:25:07 -06:00
Joel Dice
1127cb6452 fix unsigned->size_t build regression 2015-05-04 09:59:49 -06:00
Joel Dice
3b9089e265 Merge pull request #431 from joshuawarner32/all-heapdump
Always include heapdump code
2015-05-04 08:01:03 -06:00
joshuawarner32@gmail.com
1f6e7be3b0 fix openjdk build after finder size_t change
I'm not sure how we didn't catch this when merging #425, but there you are.
2015-05-03 13:25:22 -06:00
joshuawarner32@gmail.com
6be30bdaf6 always include heapdump code, to eliminate one dimension of the build matrix 2015-05-01 20:11:11 -06:00
Joshua Warner
fa63bce14d don't use x18 on arm64, where it's a reserved 'platform' register 2015-05-01 13:44:44 -06:00
Joshua Warner
1290fda6a8 fix new clang warnings (from upgrading clang) 2015-05-01 13:44:21 -06:00
Joshua Warner
1fcc097344 use size_t instead of unsigned in a bunch of appropriate places
This would theoretically break compatibility with apps using embedded
classpaths, on big-endian architectures - because of the size type
extension.  However, we don't currently support any big-endian
architectures, so it shouldn't be a problem.
2015-03-16 16:28:20 -06:00
Joel Dice
cbde34620c update copyright years 2015-03-13 12:52:59 -06:00
Joel Dice
dc7e68708f add JVM_GetResourceLookupCacheURLs
This improves support for building with openjdk=$jdk8.  Note, however,
that the Processes test does not pass, since JDK 8's
java.lang.UNIXProcess uses invokedynamic, which Avian does not yet
support.
2015-03-12 10:52:17 -06:00
Joel Dice
6c7ff9874e handle arbitrary class sizes in type-generator/main.cpp
OpenJDK 8 includes a core class (java.lang.Thread) which so many
fields that it exceeds the class size limit in type-generator dictated
by the logic responsible for calculating each class's GC object mask,
at least on 32-bit systems.  There was no fundamental need for this
limit -- it just made the code simpler.

This commit removes the above limit at the cost of slightly more
complicated code.  The original motivation for this change is that the
platform=macosx arch=i386 openjdk=$jdk8 build was failing.  However,
there doesn't seem to be a prebuild JDK 8 for 32-bit OS X anywhere on
the Internet, nor is there any obvious way to build one on a modern
Mac, so it's safe to say we won't be supporting this combination
anyway.  The problem also occurs on Linux and Windows, though,
so it needs to be fixed.
2015-03-12 10:50:03 -06:00
Joel Dice
02cfe06850 fix OpenJDK 8 class library build 2015-02-27 13:59:06 -07:00
Joel Dice
7a4cae0dde load bootstrap classes in findInterfaceMethod
In afbd4ff, I made a low-risk, but very specific fix for a more
general problem: "bootstrap" classes (i.e. classes which the VM has
built-in knowledge of) need to be loaded from the classpath before any
of their methods are called.  Based on recent testing, I found there were
more cases than I previously thought where the VM tries to call methods on
"unloaded" bootstrap classes, so we needed a more general solution to
the problem.

This commit addresses it by closing the last (known) loophole by which
methods might be called on bootstrap classes: invokeinterface, and its
helper method findInterfaceMethod.  The fix is to check for bootstrap
classes in findInterfaceMethod and load the full versions if
necessary.  This process may lead to garbage collection and/or thrown
exceptions, which made me nervous about cases of direct or indirect
calls to findInterfaceMethod not expecting those events, which is why
I hadn't used that approach earlier.  However, it turns out there were
only a few places that made non-GC-safe calls to findInterfaceMethod,
and a bit of code rearrangement fixed that.
2015-02-06 13:51:32 -07:00
Joel Dice
c2a0210c7b fix ARM64 iOS JNI crashes
As documented at
https://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html,
the ARM64 iOS ABI differs from the generic ABI in a few important
ways.  Specifically, arguments passed via the stack are aligned
according to their natural alignment instead of 8 bytes.  The VM's
dynamic call code was aligning each argument to 8 bytes, so native JNI
code couldn't find them in their expected places.

Also, we weren't setting the "os.arch" system property on ARM64, so I
fixed that too.
2015-02-05 17:20:53 -07:00
Joel Dice
afbd4ff303 fix crash when calling Class.getDeclaredMethods using the OpenJDK class library
This method ends up defering to JVM_GetClassDeclaredMethods, which
creates an array of java.lang.reflect.Method instances and then
calling getName on each one through the java.lang.reflect.Member
interface.  However, Method is a "bootstrap" class, meaning the VM has
built-in knowledge of it and includes a tentative version built-in but
must load the real version from the classpath at runtime before
invoking methods on it.  Normally this happens naturally when Method
instances are created in Java code, but here we're creating them in
the VM instead, which doesn't automatically cause the real class to be
loaded.  So we must do so explicitly.
2015-01-22 12:02:28 -07:00
Joel Dice
bbd4c58f91 align stack size for vmNativeCall to 16 on ARM
The ARM64 ABI(s) require this, and it doesn't hurt to do it on 32-bit
ARM as well.
2015-01-21 14:10:25 -07:00
Joel Dice
df0085ada5 use unconditional branch to stack overflow thunk on ARM64
On ARM64, conditional branches to immediate offsets can span no more
than 2^19 instructions.  In the case of the stack overflow check,
which wants to do a conditional branch from every non-leaf method to a
handler, this can be a problem, especially when compiled code grows
large as with a bootimage=true build against the OpenJDK class
library.  Therefore, we use an unconditional branch to reach the
handler on this platform.
2015-01-20 16:54:29 -07:00
Joel Dice
8ee7e8124a fix broken interpreter build due to out-of-order class initialization
When we initialize the vtables for bootstrap Java classes such as
java.lang.NullPointerException (i.e. classes which the VM has built-in
knowledge of), we assign the superclass's vtable to any class which
has no declared virtual methods of its own.  However, that vtable will
be null if we haven't initialized the superclass yet.  Therefore, we
must order this process such that no class is initialized until after
all its superclasses.
2015-01-15 17:13:46 -07:00
Joel Dice
4509e29abb fix method interception bug
When we intercept a method (i.e. when the VM wants to run its own code
instead of whatever the classpath provides for that method), we make a
clone of the original method so we can later call it from the
intercepting code if appropriate.  We also set the ACC_NATIVE flag on
the original method to ensure that our intercepting code is always
used in preference to the classpath version.  However, we need to set
that flag *after* we make the clone, or else the clone will also have
the ACC_NATIVE flag set, which is not what we want.

We never noticed this before because classpath versions of all the
methods we intercept as of Java 7 are either native or are never
called from their VM-specified replacements.  However, some of those
native methods are non-native in later versions of Java, so the bug
has become apparent.
2015-01-12 09:54:11 -07:00
Joshua Warner
f6e7a29f09 Merge pull request #392 from lostdj/patch-10
classpath-openjdk: Fix freeZipFileEntry()
2015-01-11 13:05:32 -07:00
Timofey Lagutin
da01d20c19 classpath-openjdk: Fix freeZipFileEntry()
Those ZipFile::Entries are part of ZipFile instance itself and will fail to free(). See :1504 and :1520 in openZipFile().
2015-01-11 22:49:15 +03:00
Timofey Lagutin
97734af72d classpath-openjdk: Fix getZipFileEntry()
'addSlash' argument was incorrectly understood: it is supposed to add slash only on retry (see ZIP_GetEntry2() zip_util.c in OpenJDK).
2015-01-11 21:44:41 +03:00
Joel Dice
80ce92a999 fix iOS ARM64 build 2014-12-30 17:03:58 -07:00
Joel Dice
c9026a6053 add continuations support for ARM64
Also, replace some preprocessor conditionals with C++ conditionals and
add some todo comments and sample code for future work towards better
ABI compatibility in the JIT compiled code.
2014-12-30 15:31:52 -07:00
Joel Dice
e3ea60fc31 fix ARM64 tails=true build 2014-12-30 09:37:26 -07:00