Commit Graph

733 Commits

Author SHA1 Message Date
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
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
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
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
Joshua Warner
1290fda6a8 fix new clang warnings (from upgrading clang) 2015-05-01 13:44:21 -06:00
Joel Dice
cbde34620c update copyright years 2015-03-13 12:52:59 -06: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
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
joshuawarner32@gmail.com
02d1a83ad9 rename lir::Register to lir::RegisterPair 2014-12-09 08:19:43 -07:00
joshuawarner32@gmail.com
2939480a65 begin renaming lir:: types 2014-12-09 08:19:43 -07:00
Joel Dice
f347414675 abort if JIT triggered when AVIAN_AOT_ONLY is defined
If AVIAN_AOT_ONLY is defined and the VM is asked to compile a method
anyway, we should abort immediately rather than let it crash later
(e.g. due to an access violation on a non-jailbroken iPhone).  This
makes debugging such issues a bit easier since the failure will come
earlier and with a more obvious cause.
2014-09-22 16:35:53 -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
8b83de8985 add avian.Machine.tryNative
This function allows you to call native code such that any
SIGSEGV/SIGBUS/SIGFPE/EXC_ACCESS_VIOLATION/etc. raised by that code is
transformed into a Java exception and thrown by tryNative.  Note that
this effectively results in a longjmp out of whatever function raised
the exception, so any C++ destructors or other cleanup code will not
be run.
2014-08-19 14:03:46 -06:00
Joshua Warner
31de9a48c9 reformat 2014-07-24 10:09:29 -06:00
Joshua Warner
1ad1fe9048 use enum class in ir 2014-07-24 10:09:29 -06:00
Joshua Warner
060b5c8f13 use c++11 variadic templates in Compiler::call 2014-07-24 10:09:29 -06:00
Joshua Warner
f3968d2401 fix compiler problems discovered in openjdk-src arm bootimage build
This particular problem was introduced in the recent "compiler types" refactor.
It's unclear why it wasn't encountered before now.

Note that the full, unproguarded bootimage build is still blocked by #305
2014-07-22 15:38:43 -06:00
Joshua Warner
fa1e3d74c0 reduce Allocator interface 2014-07-16 18:51:29 -06:00
Joshua Warner
2d0ac3ac17 reduce vm::Zone interface 2014-07-16 18:41:02 -06:00
Joshua Warner
80cf745424 move executable allocator out of System class 2014-07-16 18:40:57 -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
8a4b043ee3 generate makeZeroed method, to return a zero-initialzed instance of a Gc* class 2014-07-11 13:47:43 -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
cc4eaae706 use setters in compile.cpp 2014-07-11 13:25:21 -06:00
Joshua Warner
ed1f34dca3 formalize MyProcessor::roots (for Compiler) in types.def 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
a1583f1ecc touch up type safety in types.def 2014-07-11 13:25:20 -06:00
Joshua Warner
c796bdbde4 add bootimage-generator/main.cpp changes 2014-07-11 13:25:20 -06:00
Joshua Warner
924f242e66 add compile.cpp changes 2014-07-11 13:25:20 -06:00
Joshua Warner
1e201e54fc staticly type GcContinuation* 2014-07-11 13:25:20 -06:00
Joshua Warner
b8ddc779a2 staticly type GcReference 2014-07-11 13:25:20 -06:00
Joshua Warner
bb331e9414 make callNode and methodRuntimeData.native better statically typed 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