Permalink
Browse files

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.
  • Loading branch information...
1 parent 9918ea6 commit a09892654714f1f80c36a74bfc1e3fe5a8cd2bd4 @dicej dicej committed Apr 19, 2013
Showing with 38 additions and 1 deletion.
  1. +3 −0 src/avian/machine.h
  2. +6 −0 src/classpath-android.cpp
  3. +6 −0 src/classpath-avian.cpp
  4. +15 −0 src/classpath-openjdk.cpp
  5. +3 −1 src/machine.cpp
  6. +5 −0 test/Misc.java
View
@@ -1593,6 +1593,9 @@ class Classpath {
object calleeMethodName, object calleeMethodSpec) = 0;
virtual void
+ shutDown(Thread* t) = 0;
+
+ virtual void
dispose() = 0;
};
@@ -470,6 +470,12 @@ class MyClasspath : public Classpath {
}
virtual void
+ shutDown(Thread*)
+ {
+ // ignore
+ }
+
+ virtual void
dispose()
{
if (tzdata) {
View
@@ -187,6 +187,12 @@ class MyClasspath : public Classpath {
}
virtual void
+ shutDown(Thread*)
+ {
+ // ignore
+ }
+
+ virtual void
dispose()
{
allocator->free(this, sizeof(*this));
View
@@ -898,6 +898,21 @@ class MyClasspath : public Classpath {
}
virtual void
+ shutDown(Thread* t)
+ {
+ object c = resolveClass
+ (t, root(t, Machine::BootLoader), "java/lang/Shutdown", false);
+
+ if (c) {
+ object m = findMethodOrNull(t, c, "shutdown", "()V");
+
+ if (m) {
+ t->m->processor->invoke(t, m, 0);
+ }
+ }
+ }
+
+ virtual void
dispose()
{
allocator->free(buffer, bufferSize);
View
@@ -2315,7 +2315,7 @@ parseAttributeTable(Thread* t, Stream& s, object class_, object pool)
(&byteArrayBody(t, className(t, class_), 0),
&byteArrayBody(t, innerClassReferenceInner(t, reference), 0)))
{
- classFlags(t, class_) |= flags;
+ classFlags(t, class_) = flags;
}
}
@@ -3321,6 +3321,8 @@ shutDown(Thread* t)
setRoot(t, Machine::ShutdownHooks, 0);
+ t->m->classpath->shutDown(t);
+
object h = hooks;
PROTECT(t, h);
for (; h; h = pairSecond(t, h)) {
View
@@ -259,5 +259,10 @@ public static void main(String[] args) {
expect((Baz.class.getModifiers() & java.lang.reflect.Modifier.STATIC)
!= 0);
+
+ expect((Protected.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC)
+ == 0);
}
+
+ protected class Protected { }
}

0 comments on commit a098926

Please sign in to comment.