Commit Graph

225 Commits

Author SHA1 Message Date
Joel Dice
1735a7976a do not omit calls to empty methods which may trigger class initialization
There's a small optimization in compileDirectInvoke which tries to
avoid generating calls to empty methods.  However, this causes
problems for code which uses such a call to ensure a class is
initialized -- if we omit that call, the class may not be
initialized and any side effects of that initialization may not
happen when the program expects them to.

This commit ensures that the compiler only omits empty method calls
when the target class does not need initialization.  It also removes
commented-out code in classpath-openjdk.cpp which was responsible for
loading libmawt proactively; that was a hack to get JogAmp to work
before we understood what the real problem was.
2014-02-10 08:40:14 -07:00
Joel Dice
789c36a459 move Unsafe.putObjectVolatile and putOrderedObject implementations
This makes them available to all class libraries, not just OpenJDK.
2014-01-02 18:00:53 -07:00
Joel Dice
15906ddb12 fix build regression on platforms with no native 64-bit CAS
Unsafe.compareAndSwapLong was moved from classpath-openjdk.cpp to
builtin.cpp, but the fieldForOffset helper function was not, which
only caused problems when I tried to build for ARM.  This commit moves
said helper function, along with Unsafe.getVolatileLong, which also
uses it.
2013-12-18 11:06:15 -07:00
Simon Ochsenreither
55e9923ee6 Move Unsafe.compareAndSwapLong from ...
... classpath-openjdk.cpp to builtin.cpp.
2013-12-18 05:19:45 +01:00
Joshua Warner
9a899a2e4a fix FileInputStream for newer openjdk7 versions 2013-12-07 16:22:08 -07:00
Joel Dice
7056315c18 fix various Android test suite regressions and add more reflection tests
Most of these regressions were simply due to testing a lot more stuff,
esp. annotations and reflection, revealing holes in the Android
compatibility code.  There are still some holes, but at least the
suite is passing (except for a fragile test in Serialize.java which I
will open an issue for).

Sorry this is such a big commit; there was more to address than I
initially expected.
2013-12-06 18:48:47 -07:00
Joshua Warner
2800ffe826 rename JNIEXPORT to AVIAN_EXPORT in common.h, to avoid conflicting with jni.h 2013-11-08 08:35:17 -07:00
Geoff Nixon
69ea1f5721 Bugfixes for Mac OS X, etc. 2013-10-31 01:35:56 -07:00
Joel Dice
a9d9bc5d20 fix Clang warnings 2013-07-03 13:33:46 -07:00
Joel Dice
87b02eb949 update copyright years
Previously, I used a shell script to extract modification date ranges
from the Git history, but that was complicated and unreliable, so now
every file just gets the same year range in its copyright header.  If
someone needs to know when a specific file was modified and by whom,
they can look at the Git history themselves; no need to include it
redundantly in the header.
2013-07-02 20:52:38 -06:00
Joel Dice
b3cb20d6eb JVM_GetDeclaredClasses and JVM_GetClassInterfaces should return instances of Class[], not Object[] 2013-06-06 18:37:05 -06:00
Joel Dice
4a69496ab4 perform any necessary argument conversion in JVM_NewInstanceFromConstructor
We must use the same utility function as JVM_InvokeMethod to ensure
that primitive arguments are unboxed when necessary.
2013-05-13 14:27:39 -06:00
Joel Dice
4b0bbd85e8 fix sun.misc.Unsafe.arrayIndexScale implementation
The original implementation was based on the assumption that the
passed class would be the array element type, whereas it is actually
the array type itself.
2013-05-13 14:25:59 -06:00
Joel Dice
7e2d265fb9 filter flags argument to JVM_Open
The class library may pass non-standard flags to JVM_Open which will
confuse the OS if we pass them through, so we must filter them out.
2013-05-13 13:11:12 -06:00
Joel Dice
6d5fbdeb7b provide stub for JVM_UnloadLibrary
It may leak file handles under certain circumstances to do nothing in
JVM_UnloadLibrary, but, for now, an empty implementation is more
useful than one that aborts the process.
2013-05-13 13:08:40 -06:00
Joel Dice
419ac24963 don't load libmawt ahead of time when starting the VM
At one point, loading libmawt ahead of time was necessary to make AWT
work, but recent versions of OpenJDK seem to take care this from Java
code, in which case loading it ahead of time causes trouble, so we
comment it out for now until we exactly when it's needed.
2013-05-13 13:05:13 -06:00
Joel Dice
435dbbc874 add stub implementation of JVM_CurrentClassLoader 2013-05-10 11:29:20 -06:00
Joel Dice
529c7a17fb add support for the RuntimeVisibleParameterAnnotations attribute 2013-04-30 22:55:59 -06:00
Joel Dice
b1840a297d implement Unsafe.{put|get}Char 2013-04-30 22:54:45 -06:00
Joel Dice
af9e162827 fix OpenJDK build regression due to recent Android classpath refactoring 2013-04-30 22:53:56 -06:00
Joel Dice
4e12847858 code rearrangment to improve state of Android libcore tests
This mainly moves several sun.misc.Unsafe method implementations from
classpath-openjdk.cpp to builtin.cpp so that the Avian and Android
builds can use them.

It also replaces FinalizerReference.finalizeAllEnqueued with a no-op,
since the real implementations assumes too much about how the VM
handles (or delegates) finalization.
2013-04-23 13:47:15 -06:00
Joel Dice
a18452f6c9 implement JVM_ConstantPoolGetFloatAt
This commit also simplifies JVM_ConstantPoolGetDoubleAt, which cannot
throw an exception and thus need not go through vmRun.
2013-04-22 21:23:32 -06:00
Joel Dice
e3fe9099a2 filter InnerClasses attribute for relevant classes in JVM_GetDeclaredClasses
The InnerClasses attribute may have entries for classes declared
inside classes we don't care about, so we must check each entry's
outer class reference and make sure it matches the one we do care
about.
2013-04-22 21:20:21 -06:00
Joel Dice
a098926547 run Shutdown.shutdown on exit when using OpenJDK library
The OpenJDK library wants to track and run the shutdown hooks itself
rather than let the VM do it, so we need to tell it when we're
exiting.

Also, in machine.cpp we need to use only the modifiers specified in
the InnerClasses attribute for inner classes rather than OR them with
the flags given at the top level of the class file.
2013-04-19 13:00:47 -06:00
Joel Dice
e6b6edfc25 ignore instance variable for static method invocations 2013-04-18 11:25:29 -06:00
Joel Dice
81d7786716 fix Class.getModifiers for inner classes and implement JVM_GetDeclaringClass and JVM_GetEnclosingMethodInfo properly
This fixes a couple of tests in the Scala test suite
(run/reflection-modulemirror-toplevel-badpath.scala and
run/reflection-constructormirror-nested-good.scala).
2013-04-17 15:12:58 -06:00
Joel Dice
aa513c2c1d set default file.encoding to UTF-8 in classpath-openjdk.cpp
This default makes more sense than ASCII, which is what it had been.
2013-04-16 19:35:21 -06:00
Joel Dice
2c902a26ec handle non-ASCII strings properly in MyClasspath::makeString 2013-04-09 18:44:54 -06:00
Joel Dice
83670d1df7 implement JVM_ConstantPoolGetLongAt 2013-04-09 18:44:34 -06:00
Joel Dice
73547db737 throw IllegalArgumentException in JVM_InvokeMethod on type mismatch 2013-04-09 18:44:34 -06:00
Joel Dice
4777d1b6be fix Windows openjdk-src build regression 2013-03-26 09:53:47 -06:00
Joel Dice
c80ffa041d ensure that we can intercept static Java methods in bootimage build
Timezone code was broken in the Android class library bootimage build
because the code we use to intercept loading the tzdata file wasn't
working.  The reason is have no way of intercepting static methods at
runtime in the bootimage build without telling the bootimage-generator
we're going to do it ahead of time.  So now we do tell it so.

This commit also removes the need to intercept Thread methods since we
can update Thread.vmThread in VMThread.create instead.
2013-03-15 13:28:01 -06:00
Joel Dice
5d3dc707cb briefly enter idle state in get*Volatile
In order for a thread to enter the "exclusive" state such that no
other threads are active in the VM, it must wait for all active
threads to enter the "idle" state.  In order for this to happen in a
timely manner, threads must check frequently to see if a thread is
waiting to enter the exclusive state.  These checks happen at every
memory allocation, wait, sleep, native call, etc.  However, if a
thread is in a busy loop that does none of those things, it will block
any other thread from entering that state.

The proper way to address this is to detect such loops (or tail
recursion in tail-call-optimized builds) at compile or interpret time
and insert explicit checks.  This hasn't been a high priority thus
far, though, since we had yet to encounter such code in the wild.

Now, however, we find that scala.concurrent.forkjoin.ForkJoinPool.scan
(and possibly some versions of java.util.concurrent.ForkJoinPool.scan,
on which we assume the former is based) has just such a loop.
Fortunately, that loop calls Unsafe.getObjectVolatile, which the VM
implements and thus can treat as a checkpoint.  That's the workaround
we use in this patch.
2013-03-08 18:21:12 -07:00
Joel Dice
ca84dd26f1 fix System.loadLibrary for OpenJDK tails=true build 2013-03-05 15:43:49 -07:00
Joel Dice
84f99f0dca remove thread from thread group on termination
In the OpenJDK library, ThreadGroup maintains an array of all Threads
in that group, so the VM must explicitly remove threads as they exit
or else neither they nor any objects they reference will be eligable
for GC.
2013-03-05 09:06:19 -07:00
Joel Dice
5e2d00010b move headers from src to src/avian
This is necessary to avoid name conflicts on various platforms.  For
example, iOS has its own util.h, and Windows has a process.h.  By
including our version as e.g. "avian/util.h", we avoid confusion with
the system version.
2013-02-27 13:33:29 -07:00
Joel Dice
44defda878 fix unused parameter error 2013-02-27 12:10:10 -07:00
Joel Dice
3c1db46c57 don't throw an error if the mawt library can't be loaded 2013-02-27 11:34:43 -07:00
Joel Dice
025b628894 Merge remote-tracking branch 'github/master' into dicej 2013-02-25 16:43:09 -07:00
Joel Dice
fddd3ec49d fix openjdk-src build regression due to RUNTIME_ARRAY changes 2013-02-25 10:38:06 -07:00
Joel Dice
686c2352c1 all tests now pass for Android class library build 2013-02-22 17:23:59 -07:00
Joel Dice
b32dfb674c fix merge fallout (take 2) 2013-02-22 14:54:13 -07:00
Joel Dice
9060a31348 Merge remote-tracking branch 'github/master' into dicej
Conflicts:
	src/classpath-openjdk.cpp
2013-02-22 14:43:20 -07:00
Joel Dice
d152f8cf74 fix openjdk build 2013-02-22 14:41:24 -07:00
Joel Dice
2f549dd3a3 fix RUNTIME_ARRAY_BODY regressions in classpath-openjdk.cpp 2013-02-22 14:20:09 -07:00
Joel Dice
42d39b1af1 more Android class library work 2013-02-21 15:37:17 -07:00
Joel Dice
d414fd4c7b more progress on Android class library port
Hello.java works.  Yay.
2013-02-20 10:22:40 -07:00
Joshua Warner
5dd770d7ea rename cast -> fieldAtOffset 2013-02-10 18:07:03 -07:00
Joel Dice
5dcf6eae5a fix GC safety issue in MyClasspath::updatePackageMap 2013-02-03 20:29:24 -07:00
Joel Dice
3db9e73aa1 fix GC safety issues in classpath-openjdk.cpp 2013-02-03 15:19:35 -07:00
Joel Dice
80c8940b7f ensure joining threads are always notified when a thread exits
Previously, we'd only do this if the thread exited without throwing an
exception.  Now we do it regardless.
2013-02-03 15:18:32 -07:00
Joel Dice
1890e348fb fix handling of classe, method, and field names with non-ASCII characters 2013-02-03 14:10:47 -07:00
Joel Dice
2131adf3aa fix Windows OpenJDK build 2013-01-25 08:07:47 -07:00
Joel Dice
36eee724c9 check argument types in JVM_InvokeMethod
Method.invoke must throw an IllegalArgumentException if it receives
the wrong number or types of arguments, and since this isn't done by
the OpenJDK class library, we must do it in the VM.
2013-01-24 12:16:41 -07:00
Joel Dice
0adccdc99c return unadorned filename from JVM_GetSystemPackage
Package.defineSystemPackage expects a filename, not a URL.
2013-01-24 12:16:40 -07:00
Joel Dice
9f22a701cc load libmawt.so proactively when booting the VM for OpenJDK
This library is placed in the xawt subdirectory of jre/lib/$arch on
POSIX systems, so it isn't found automatically when third-party
libraries which depend on it are loaded.  The simplest way to ensure
that it's found seems to be to just load it when the VM starts up.
2012-12-20 12:30:15 -07:00
Joel Dice
d200019d10 implement JNI reflection methods
These include FromReflectedMethod, ToReflectedMethod,
FromReflectedField, and ToReflectedField.
2012-12-19 12:39:33 -07:00
Joel Dice
1ce012aa68 fix abort in classpath-openjdk.cpp due to buffer overflow
This addresses the case where -Djava.home=<some really long path>.

https://github.com/ReadyTalk/avian/issues/15
2012-10-03 09:43:51 -06:00
Joel Dice
1d4c9d32fb return null from JNIEnv::GetSuperclass for interfaces per spec 2012-09-28 15:03:14 -06:00
Joel Dice
3693201911 make JVM_GetSystemPackage a bit smarter
The original stub implementation just echoed back its argument, but
that confused URLClassLoader when dealing with sealed JARs --
returning a non-null value for a non-system class from
JVM_GetSystemPackage made URLClassloader think it had already loaded a
class from a package which was supposed to be sealed, resulting in
SecurityExceptions which ultimately triggered NoClassDefFoundErrors.
The solution is to only return non-null values for actual system
classes.
2012-09-24 17:43:34 -06:00
Joel Dice
e20c5cd9c6 fix a couple of OpenJDK reflection bugs
We weren't wrapping exceptions thrown by invoked methods in
InvocationTargetExceptions in JVM_InvokeMethod or
JVM_NewInstanceFromConstructor.  Also, JVM_GetCallerClass is supposed
to ignore Method.invoke frames when walking the stack.
2012-09-22 20:22:33 -06:00
Joel Dice
c918cbced1 fix sun.misc.Unsafe.getLongVolatile for static fields on 32-bit platforms
The existing code did not handle static field lookups for
synchronization on 32-bit systems, which is necessary because such
systems generally don't support atomic operations on 64-bit values.
2012-09-11 19:28:02 -06:00
Xerxes Rånby
db0c14d742 Set java.vm.info based on makefile info= and
set java.vm.version based on makefile version=
in order to display relevant OpenJDK -version information.

Signed-off-by: Matthias Klose <doko@ubuntu.com>
Signed-off-by: Xerxes Rånby <xerxes@zafena.se>
2012-09-05 15:30:49 +02:00
Joel Dice
3f039864d1 fix memcpy argument order bug in jvmConstantPoolGetDoubleAt 2012-08-29 12:10:31 -06:00
Joel Dice
7534eecdb3 implement JVM_ConstantPoolGetDoubleAt 2012-08-29 18:34:28 -06:00
Joel Dice
374bdb3726 implement Runtime.maxMemory for OpenJDK port
Some apps refuse to run if Runtime.maxMemory returns a value that's
"too small", so our stub implementation returning zero was not
sufficient.  Now we return the actual heap size limit in bytes.
2012-08-29 18:32:45 -06:00
Joel Dice
8c48a44e54 set main thread context classloader correctly for OpenJDK port
sun.misc.Launcher has its own idea about what the application
classloader should be, but we need to override it with the system
classloader created by the VM.  This is achieved by running
Launcher.getLauncher (which has the side effect of setting
Thread.contextClassLoader) and then overriding it.
2012-08-29 18:27:37 -06:00
Joel Dice
47503854d5 Thread.sleep(0) should not sleep indefinitely
Our implementation uses Object.wait(long) to implement Thread.sleep,
which had the side effect of interpreting zero as infinity.  However,
for Thread.sleep, zero just means zero.  I assume that doesn't mean
"don't sleep at all", though, or else the app wouldn't have called
Thread.sleep in the first place, so this patch sleeps for one
millisecond when zero is passed -- just enough to yield the processor
for a bit.  Thread.yield might be a better choice in this case, but I
assume the app would have called that directly if that's what it
wanted.
2012-08-12 11:17:59 -06:00
Joel Dice
01be4b23bb implement JNI methods needed by AWT
These include PushLocalFrame, PopLocalFrame, NewDirectByteBuffer,
GetDirectBufferAddress, and GetDirectBufferCapacity.
2012-08-11 06:56:19 -06:00
Joel Dice
2642a167e2 fix Class.getPackage for system classes in OpenJDK build 2012-08-11 06:46:24 -06:00
Damjan Jovanovic
53b15d1bca look for initIDs in SunFontManager instead of FontManager
OpenJDK 7 has refactored this code relative to OpenJDK 6, and now
FontManager is an interface, with SunFontManager providing a (partial)
implementation.
2012-08-05 19:31:20 -06:00
Damjan Jovanovic
59d7f5a47a fix java.library.path on the ARM platform
On the ARM platform, Avian compiled to use OpenJDK gets this error on
startup:
java/lang/UnsatisfiedLinkError: no zip in java.library.path
  at java/lang/ClassLoader.loadLibrary (line 1860)
  at java/lang/Runtime.loadLibrary0 (line 845)
  at java/lang/System.loadLibrary (line 1084)
  at java/lang/System.initializeSystemClass (line 1145)

Using strace shows why:
[pid 22431]
stat64("/usr/lib/jvm/java-7-openjdk-armhf/jre/lib/i386/libzip.so",
0xbee377e0) = -1 ENOENT (No such file or directory)

The attached patch uses "arm" instead of "i386" in that path. This fixes the
problem.
2012-08-04 07:31:54 -06:00
Damjan Jovanovic
c1aa0b46b5 add support for FreeBSD 2012-08-02 10:41:41 -06:00
Joel Dice
5a5a6a7795 fix C++11 errors and aliasing warning 2012-06-13 19:10:28 -06:00
Joel Dice
7bfb5a6287 fix native method name ambiguity
sun.misc.Unsafe now has two native getByte methods: one which takes a
long and another which takes an Object and a long.  Thus, we need to
decorate each version with its parameter signature so we don't
accidentally call the wrong one at runtime.
2012-06-12 16:33:31 -06:00
Joel Dice
fa8ba2afc8 fix build for recent versions of OpenJDK 7
As of the latest code from the jdk7u-dev Mercurial repository,
java.lang.String no longer has offset or length fields.  Instead, the
content fits exactly into the backing char array, so offset is
implicitly zero and length is the length of the array.  The VM
previously relied on those fields being present, whereas this commit
handles the case where they are not.

In addition, I've made some changes to openjdk-src.mk to ensure that
we can build against both a stock OpenJDK 7 and an IcedTea-patched
version.
2012-06-11 23:30:22 +00:00
Joel Dice
0addd8c814 update copyright years 2012-05-11 17:43:27 -06:00
Joel Dice
e6afc6c321 set Thread.interrupted to true if thread is interrupted outside wait or sleep
This is the correct behavior according to the Thread.interrupt
JavaDoc, and it fixes an intermittent hang on exit in Eclipse.
2012-05-02 11:41:36 -06:00
Joel Dice
deeb3c694c interpret time of zero as infinity when isAbsolute is false in Unsafe.park
This behavior is not covered in the documentation, but
LockSupport.park clearly relies on it.
2012-04-25 17:47:07 -06:00
Joel Dice
1120d8f91d fix ProGuarded openjdk-src build
This makes a simple "hello, world!" app work, at least.  Further
changes may be needed for more sophisticated apps.
2012-04-10 08:18:52 -06:00
Joel Dice
4f0d275e13 run JNI_OnLoad if found in ClassLoader.loadLibrary 2012-03-18 20:10:42 -06:00
Joel Dice
0167868797 various Windows OpenJDK 7 fixes 2012-03-17 18:47:22 -06:00
Joel Dice
8abe9bf469 fix memory leak in freeZipFileEntry 2012-03-17 12:58:41 -06:00
Joel Dice
333b6c59d4 fix non-embedded openjdk build on OS X
The JRE lib dir for OpenJDK 7 on OS X seems to be just "lib", not
e.g. "lib/amd64" by default, so we use that now.  Also, the default
library compatibility version for libjvm.dylib is 0.0.0, but OpenJDK
wants 1.0.0, so we set it explicitly.
2012-03-16 11:01:20 -06:00
Joel Dice
d718bbf833 implement Unsafe.getByte(Object, long) 2012-03-14 12:35:22 -06:00
Joel Dice
eb9f5c6dcc Merge remote branch 'oss/master' into jdk7 2012-03-14 08:22:46 -06:00
Joel Dice
37044236d4 provide dummy implementation of JVM_GetThreadInterruptEvent 2012-03-13 10:31:08 -06:00
Joel Dice
4aefa211a3 File.createNewFile should return false if the file already exists 2012-03-13 08:26:51 -06:00
Joel Dice
3820fec9d7 fix OS X OpenJDK 7 build 2012-03-11 16:26:46 -06:00
Joel Dice
1c2f516b68 Merge remote-tracking branch 'origin/master' into jdk7
Conflicts:
	src/classpath-openjdk.cpp
2012-03-11 15:30:38 -06:00
Joel Dice
6cc0ddda7c implement JVM_HoldsLock 2012-03-11 05:06:08 -06:00
Joel Dice
04a34a75ed implement sun.misc.Unsafe.monitorEnter and monitorExit 2012-03-11 05:05:14 -06:00
Joel Dice
3e38628ad6 check superclasses in fieldForOffset, not just immediate class 2012-03-11 05:04:12 -06:00
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
c3b72a3dd5 set sun.boot.class.path property in jvmInitProperties 2012-02-29 11:46:50 -07:00
Joel Dice
747f22115f handle JMM_THREAD_ALLOCATED_MEMORY in JMX GetBoolAttribute implementation 2012-02-21 17:33:51 -07:00
Joel Dice
d94fd952e9 fix some OpenJDK update regressions 2012-02-20 17:38:41 -07:00
Joel Dice
bc5661d6f3 start work on OpenJDK 7 class library port 2012-02-18 15:17:10 -07:00
Joel Dice
c3256c2874 avoid running out of OS resources due to zombie thread accumulation
The bug here is that when a thread exits and becomes a "zombie", the
OS resources associated with it are not necessarily released until we
actually join and dispose of that thread.  Since that only happens
during garbage collection, and collection normally only happens in
response to heap memory pressure, there's no guarantee that we'll GC
frequently enough to clean up zombies promptly and avoid running out
of resources.

The solution is to force a GC whenever we start a new thread and there
are at least N zombies waiting to be disposed, where N=16 for now.
2012-02-03 12:00:02 -07:00
Joel Dice
d29513c653 fix Avian_sun_misc_Unsafe_compareAndSwapLong for platforms without atomicCompareAndSwap64
We never define atomicCompareAndSwap64 for ARM or PowerPC, and
apparently only very recent ARM chips support it, so we must fall back
to synchronization-based emulation.
2012-01-15 10:02:36 -07:00