Commit Graph

260 Commits

Author SHA1 Message Date
Joel Dice
89f6adc93c fix various classloading deadlocks and races 2010-09-22 13:58:46 -06:00
Joel Dice
17f495eb27 rework OpenJDK build to derive classpath and library path from environment
We now consult the JAVA_HOME environment variable to determine where
to find the system library JARs and SOs.  Ultimately, we'll want to
support self-contained build, but this allows Avian to behave like a
conventional libjvm.so.
2010-09-20 17:31:23 -06:00
Joel Dice
d0d53e2e10 fix custom-classloader-related concurrency problems and other bugs
The main changes in this commit ensure that we don't hold the global
class lock when doing class resolution using application-defined
classloaders.  Such classloaders may do their own locking (in fact,
it's almost certain), making deadlock likely when mixed with VM-level
locking in various orders.

Other changes include a fix to avoid overflow when waiting for
extremely long intervals and a GC root stack mapping bug.
2010-09-16 20:49:02 -06:00
Joel Dice
f485016637 implement more JVM_* methods and avoid duplicate array class loading 2010-09-14 18:52:57 -06:00
Joel Dice
d819a75f36 more work towards OpenJDK classpath support
The biggest change in this commit is to split the system classloader
into two: one for boot classes (e.g. java.lang.*) and another for
application classes.  This is necessary to make OpenJDK's security
checks happy.

The rest of the changes include bugfixes and additional JVM method
implementations in classpath-openjdk.cpp.
2010-09-14 10:49:41 -06:00
Joel Dice
cddea7187d preliminary support for using OpenJDK's class library
Whereas the GNU Classpath port used the strategy of patching Classpath
with core classes from Avian so as to minimize changes to the VM, this
port uses the opposite strategy: abstract and isolate
classpath-specific features in the VM similar to how we abstract away
platform-specific features in system.h.  This allows us to use an
unmodified copy of OpenJDK's class library, including its core classes
and augmented by a few VM-specific classes in the "avian" package.
2010-09-10 15:05:29 -06:00
Joel Dice
17c1a552d5 break each Class, Field, and Method into separate classes
In order to facilitate making the VM compatible with multiple class
libraries, it's useful to separate the VM-specific representation of
these classes from the library implementations.  This commit
introduces VMClass, VMField, and VMMethod for that purpose.
2010-09-01 10:13:52 -06:00
Joel Dice
fca98df55b fix process=interpret class initialization regression
A long time ago, I refactored the class initialization code in the VM,
but did not notice until today that it had caused the
process=interpret build to break on certain recursive initializations.
In particular, we were not always detecting when a thread recursively
tried to initialize a class it was already in the process of
initializing, leading to the mistaken assumption that another thread
was initializing it and that we should wait until it was done, in
which case we would wait forever.

This commit ensures that we always detect recursive initialization and
short-circuit it.
2010-08-04 18:27:54 -06:00
Joel Dice
3018290238 pre-allocate Thread::backupHeap for signal safety
It's not safe to use malloc from a signal handler, so we can't
allocate new memory when handling segfaults or Thread.getStackTrace
signals.  Instead, we allocate a fixed-size backup heap for each
thread ahead of time and use it if there's no space left in the normal
heap pool.  In the rare case that the backup heap isn't large enough,
we fall back to using a preallocated exception without a stack trace
as a last resort.
2010-06-19 16:40:21 -06:00
JET
c666ab58e3 Improved (should now be complete) Unicode support (UTF-8 for *nix and UTF-16 for Windows). 2010-04-20 10:03:07 -06:00
Joel Dice
c9b9db1621 reimplement Java object monitors (second try)
See commit 8120bee4dc for the original
problem description and solution.  That commit and a couple of related
ones had to be reverted when we found they had introduced GC-safety
regressions leading to crashes.

This commit restores the reverted code and fixes the regressions.
2010-02-04 17:56:21 -07:00
Joel Dice
48834be209 revert recent commits to reimplement Java object monitors
We're seeing race conditions which occasionally lead to assertion
failures and thus crashes, so I'm reverting these changes for now:

29309fb414
e92674cb73
8120bee4dc
2010-02-04 08:18:39 -07:00
Joel Dice
8120bee4dc reimplement Java object monitors to avoid running out of OS handles
Due to SWT's nasty habit of creating a new object monitor for every
task added to Display.asyncExec, we've found that, on Windows at
least, we tend to run out of OS handles due to the large number of
mutexes we create between garbage collections.

One way to address this might be to trigger a GC when either the
number of monitors created since the last GC exceeds a certain number
or when the total number of monitors in the VM reaches a certain
number.  Both of these risk hurting performance, especially if they
force major collections which would otherwise be infrequent.  Also,
it's hard to know what the values of such thresholds should be on a
given system.

Instead, we reimplement Java monitors using atomic compare-and-swap
(CAS) and thread-specific native locks for blocking in the case of
contention.  This way, we can create an arbitrary number of monitors
without creating any new native locks.  The total number of native
locks needed by the VM is bounded instead by the number of live
threads plus a small constant.

Note that if we ever add support for an architecture which does not
support CAS, we'll need to provide a fallback monitor implementation.
2010-02-01 18:40:47 -07:00
Joel Dice
805d1d13d8 mark system classloader initialized when using GNU Classpath to avoid security exceptions; only look for field in interfaces after looking in class and superclasses 2009-12-24 17:57:07 -07:00
Joel Dice
f588a62ae3 fix Classpath 0.98 compatibility issues 2009-12-22 21:34:04 -07:00
Joel Dice
2b4361c060 fix GNU Classpath build 2009-12-05 19:40:46 -07:00
Joel Dice
851187f0ce refine memory barrier implementation and usage 2009-11-30 15:38:16 +00:00
Joel Dice
0b09c6aa30 avoid busy wait when entering "exclusive" state 2009-11-29 16:53:05 -07:00
Joel Dice
6d9e1270ca fix race conditions in atomic operations 2009-11-29 09:08:07 -07:00
Joel Dice
1558b85acf second attempt to fix "idle to active" fast path
If another thread succeeds in entering the "exclusive" state while we
use the fast path to transition the current thread to "active", we
must switch back to "idle" temporarily to allow the exclusive thread a
chance to continue, and then retry the transition to "active" via the
slow path.
2009-11-28 15:35:15 -07:00
Joel Dice
3418a8bcbe fix race condition introduced in previous commit 2009-11-28 15:24:02 -07:00
Joel Dice
75934c8342 provide fast paths for common thread state transitions
These paths reduce contention among threads by using atomic operations
and memory barriers instead of mutexes where possible.  This is
especially important for JNI calls, since each such call involves two
state transitions: from "active" to "idle" and back.
2009-11-28 15:01:54 -07:00
Joel Dice
1a63b72b41 clean up float-vs.-int tracking in constant pools 2009-10-17 20:11:03 -06:00
Joel Dice
325f93b4d1 Merge branch 'master' into wip
Conflicts:

	src/compile.cpp
	src/compiler.cpp
	src/machine.h
	src/x86.cpp
2009-09-20 15:43:32 -06:00
Joel Dice
953cb69e5e move proxy and annotation code from C++ to Java
This allows code shrinkers to remove it if it's not used by the application.
2009-09-19 16:21:15 -06:00
Joel Dice
1a2eb3836c Merge branch 'master' of oss.readytalk.com:/var/local/git/avian 2009-09-18 18:01:57 -06:00
Joel Dice
7aa906d97b support runtime-visible annotations and java.lang.reflect.Proxy 2009-09-18 18:01:54 -06:00
Joel Dice
d0f8889e27 fix GC safety bugs in parseMethodTable and makeArrayClass 2009-09-18 12:20:35 -06:00
Joel Dice
b645c284b5 fix memory leak in debug build 2009-09-17 21:36:52 -06:00
Joel Dice
fcc4ff93e0 remove debug logging 2009-09-17 21:22:47 -06:00
Joel Dice
6519047342 fix bootimage build 2009-09-03 09:06:04 -06:00
Joel Dice
84ac2e417d follow reference pointer before using in in refrenceTargetUnreachable in case it points to a moved object 2009-09-01 18:32:21 -06:00
Joel Dice
4f794f533e fix handling of reachable, moved weak references in postVisit 2009-09-01 17:23:30 -06:00
Joel Dice
73dc058c14 implement StackTraceElement.getFileName properly 2009-08-27 16:28:44 -06:00
Joel Dice
1a0eef7e2d add support for building with MSVC on Windows 2009-08-26 18:26:44 -06:00
Joel Dice
4297fa04b3 run java finalizers in a separate thread to guarantee no application locks are held when doing so 2009-08-24 17:51:31 -06:00
Joel Dice
a56c1d8765 fix GC-safety bug in resolveSpec 2009-08-20 12:37:03 -06:00
Joel Dice
6196f61938 clear Thread::javaThread before entering zombie state, since clearing it in Thread::dispose is too late - the reference may already be invalid since we don't visit GC roots for zombie threads 2009-08-20 08:49:01 -06:00
Joel Dice
c4b5ecec90 implement Runtime.addShutdownHook and Thread.setDaemon; avoid segfaults due to an application calling e.g. CallStaticBooleanMethod when it really meant CallStaticVoidMethod 2009-08-19 14:27:03 -06:00
Joel Dice
01dcb1661b don't resolve all constant pool entries in linkClass - just the field and method specs 2009-08-18 15:27:21 -06:00
Joel Dice
c4edabdc02 implement ClassLoader.resolveClass and ensure class is linked in e.g. Class.getMethods; minor bugfixes 2009-08-18 14:26:28 -06:00
Joel Dice
7fcbf9d85c fix reading 2-byte UTF-8 constants 2009-08-14 08:52:31 -06:00
Joel Dice
3facd3f735 treat SoftReferences as WeakReferences; do vtable or interface table lookups as necessary in MyProcessor::invoke; various bugfixes 2009-08-13 09:17:05 -06:00
Joel Dice
db58097165 re-enable finalization 2009-08-11 10:04:41 -06:00
Joel Dice
fb5b0570c3 replace slashes with dots in class name before passing it to ClassLoader.loadClass 2009-08-11 09:20:49 -06:00
Joel Dice
28b5c46a0b fix GC safety bug in makeNewGeneral 2009-08-10 17:35:44 -06:00
Josh warner
1d3ef1fc43 Merge branch 'master' of git://oss.readytalk.com/avian, fixed problems that occured in broader testing
Conflicts:
	src/compile.cpp
	src/compiler.cpp
	src/powerpc.cpp
	src/x86.S
	src/x86.cpp
2009-08-10 13:20:23 -06:00
Joel Dice
001000364d add classloader parameter to functions which may directly or indirectly load classes; include methods inherited from interfaces (but not explicitly declared) in method tables and virtual tables of abstract classes 2009-08-10 07:56:16 -06:00
Joel Dice
d5f4811b43 check for exception after calling resolveClass in parseInterfaceTable 2009-08-04 08:50:04 -06:00
Joel Dice
f8bf83bfec fix recent regression in findInHierarchy 2009-08-04 08:42:16 -06:00