From a09892654714f1f80c36a74bfc1e3fe5a8cd2bd4 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 19 Apr 2013 13:00:47 -0600 Subject: [PATCH] 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. --- src/avian/machine.h | 3 +++ src/classpath-android.cpp | 6 ++++++ src/classpath-avian.cpp | 6 ++++++ src/classpath-openjdk.cpp | 15 +++++++++++++++ src/machine.cpp | 4 +++- test/Misc.java | 5 +++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/avian/machine.h b/src/avian/machine.h index a53d4c98f2..ae6a0368da 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -1592,6 +1592,9 @@ class Classpath { canTailCall(Thread* t, object caller, object calleeClassName, object calleeMethodName, object calleeMethodSpec) = 0; + virtual void + shutDown(Thread* t) = 0; + virtual void dispose() = 0; }; diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index bc325470b4..87fa114cf0 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -469,6 +469,12 @@ class MyClasspath : public Classpath { return true; } + virtual void + shutDown(Thread*) + { + // ignore + } + virtual void dispose() { diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 64c56fc389..ef16a767c1 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -186,6 +186,12 @@ class MyClasspath : public Classpath { return true; } + virtual void + shutDown(Thread*) + { + // ignore + } + virtual void dispose() { diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index c85c8a184c..1a70816295 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -897,6 +897,21 @@ class MyClasspath : public Classpath { (&byteArrayBody(t, calleeClassName, 0)))); } + 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() { diff --git a/src/machine.cpp b/src/machine.cpp index 3f66a3785c..4e6ccd8ce0 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -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)) { diff --git a/test/Misc.java b/test/Misc.java index 66f290f177..91195d5f13 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -259,5 +259,10 @@ public class Misc { expect((Baz.class.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0); + + expect((Protected.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC) + == 0); } + + protected class Protected { } }