Commit Graph

456 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
aacbd7cc7a support Java 8 default interface methods 2016-05-14 13:32:42 -06: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
66712a8cff add invokedynamic support to interpreter 2015-08-06 17:22:14 -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
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
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
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
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
d930fbcda2 ensure Object.notify is available for Android classpath build and reduce duplication 2014-10-10 07:38:41 -06:00
Joel Dice
32aefaf421 ensure Thread::flags is always updated atomically
Since this field is sometimes updated from other threads, it is
essential that we always update it atomically.
2014-08-20 09:49:00 -06:00
Joel Dice
4c8f3933f5 fix order of operations regression in referenceTargetUnreachable
We need to dereference the GcJreference** before we change what it
points to.  The code was mistakenly reordered in the recent type
refactoring.
2014-07-17 17:53:36 -06:00
Joshua Warner
fa1e3d74c0 reduce Allocator interface 2014-07-16 18:51:29 -06:00
Joel Dice
2a43e68c16 fix all the bugs
So there I was, planning to just fix one little bug: Thread.holdsLock
and Thread.yield were missing for the Android class library.  Easy
enough, right?  So, I added a test, got it passing, and figured I'd go
ahead and run ci.sh with all three class libraries.  Big mistake.

Here's the stuff I found:

 * minor inconsistency in README.md about OpenSSL version

 * untested, broken Class.getEnclosingMethod (reported by Josh)

 * JNI test failed for tails=true Android build

 * Runtime.nativeExit missing for Android build

 * obsolete assertion in CallEvent broke tails=true Android build

 * obsolete superclass field offset padding broke bootimage=true Android build

 * runtime annotation parsing broke bootimage=true Android build
   (because we couldn't modify Addendum.annotationTable for classes in
   the heap image)

 * ci.sh tried building with both android=... and openjdk=..., which
   the makefile rightfully balked at

Sorry this is all in a single commit; I didn't expect so many
unrelated issues, and I'm too lazy to break them apart.
2014-07-12 16:57:24 -06:00
Joshua Warner
80f19abf3a put all commented code in if(false) blocks instead; fix ensuing broken code 2014-07-12 10:16:03 -06:00
Joshua Warner
836cc41320 bulk, global reformat 2014-07-11 13:25:22 -06:00
Joshua Warner
7642b94308 reformat changes since master 2014-07-11 13:25:22 -06:00
Joshua Warner
cbad6931af retypedef object to GcObject*, remove (almost?) all unnecessary reinterpret_casts 2014-07-11 13:25:22 -06:00
Joshua Warner
b0490b8233 finish using setters 2014-07-11 13:25:22 -06:00
Joshua Warner
40e71a4856 use setters in machine.cpp 2014-07-11 13:25:21 -06:00
Joshua Warner
880b9fa910 use setters in machine.h 2014-07-11 13:25:21 -06:00
Joshua Warner
052f2498aa formalize Machine::roots in types.def 2014-07-11 13:25:21 -06:00
Joshua Warner
b4798550a3 add machine.cpp changes 2014-07-11 13:25:20 -06:00
Joshua Warner
4df8f59f3c staticly type finalizer and cleaner 2014-07-11 13:25:20 -06:00
Joshua Warner
b8ddc779a2 staticly type GcReference 2014-07-11 13:25:20 -06:00
Joshua Warner
1da8170c66 apply jnienv + java-common changes 2014-07-11 13:25:19 -06:00
Joshua Warner
9c93c5989c apply classpath-common.h changes 2014-07-11 13:25:19 -06:00
Joshua Warner
00e2307c39 apply machine.h changes 2014-07-11 13:25:19 -06:00
Joshua Warner
9ffbd7e9fe staticly type GcClassLoader instances 2014-07-11 13:25:19 -06:00
Joshua Warner
6a0502bbfe add util.cpp/.h changes 2014-07-11 13:25:19 -06:00
Joshua Warner
51368651dc better statically type Processor interface 2014-07-11 13:25:19 -06:00
Joshua Warner
0ec87c6aa1 statically type Addendum.pool better 2014-07-11 13:25:19 -06:00
Joshua Warner
9f5912c2b6 add stronger typing to method.code 2014-07-11 13:25:19 -06:00
Joshua Warner
9248f8f8ad add stronger typing to code.singleton 2014-07-11 13:25:18 -06:00
Joshua Warner
4754a92b75 split code.stackMap out of code.pool use 2014-07-11 13:25:18 -06:00
Joshua Warner
083dc17810 add stronger typing to code.lineNumberTable 2014-07-11 13:25:18 -06:00
Joshua Warner
194e3b2701 add VMClass changes 2014-07-11 13:25:18 -06:00
Joshua Warner
9b36dca846 generate better typed accessors from type-generator (and switch to using standard library there) 2014-07-11 13:25:17 -06:00
Joshua Warner
263e349cae rename assert to assertT, to avoid conflict with std assert macro 2014-07-11 09:32:57 -06:00
Joshua Warner
b5699cc9dc move Machine::*Type to GcObject::*Type 2014-07-11 09:32:55 -06:00
Joel Dice
1b83ef7eb3 only wrap Exceptions in ExceptionInInitializerErrors, not Errors 2014-07-10 13:43:10 -06:00
Joel Dice
4dc76a50a2 fix case of JNIEnv::FindClass called from JNI_OnLoad
If an JNI_OnLoad implementation calls FindClass when using the OpenJDK
class library, the calling method on the Java stack will be
ClassLoader.loadLibrary.  However, we must use the class loader of the
class attempting to load the library in this case, not the system
classloader.

Therefore, we now maintain a stack such that the latest class to load
a library in the current thread is at the top, and we use that class
whenever FindClass is called by ClassLoader.loadLibrary (via
JNI_OnLoad).

Note that this patch does not attempt to address the same problem for
the Avian or Android class libraries, but the same strategy should
work for them as well.
2014-06-23 17:25:42 -06:00
Joshua Warner
34962ff334 Merge pull request #245 from dicej/jdk8
add support for using the OpenJDK 8 class library
2014-04-24 18:50:38 -06:00
Joel Dice
7de555c797 add support for using the OpenJDK 8 class library
This ensures that all tests pass when Avian is built with an
openjdk=$path option such that $path points to either OpenJDK 7 or 8.

Note that I have not yet tried using the openjdk-src option with
OpenJDK 8.  I'll work on that next.
2014-04-23 15:36:56 -06:00
Joel Dice
9b7d0d1624 update copyright years 2014-04-23 15:33:41 -06:00
Vasily Litvinov
74209edb7d Replacing strcpy with memcpy - should be slightly faster because we're forced to know strlen, so no need in byte-by-byte copying 2014-04-10 01:02:11 +04:00
Vasily Litvinov
5828ef1d46 Fixing property copying 2014-04-09 16:02:48 +04:00
Ilya Mizus
6e3b170393 Trying to solve the properties memory problem 2014-04-09 10:16:53 +04:00