# HG changeset patch # User Thomas Wuerthinger # Date 1290797105 -3600 # Node ID 5571b97fc1ec3f82b0c99b838601c67078510551 # Parent 30e1f67703da344fcea78f01cd51b22c2ba09bd1 More JNI global handle clean ups. diff -r 30e1f67703da -r 5571b97fc1ec c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java --- a/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java Fri Nov 26 13:52:15 2010 +0100 +++ b/c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotXirGenerator.java Fri Nov 26 19:45:05 2010 +0100 @@ -372,13 +372,13 @@ return asm.finishTemplate("putfield<" + kind + ">"); } XirParameter fieldOffset = asm.createConstantInputParameter("fieldOffset", CiKind.Int); + if (kind == CiKind.Object) { + verifyPointer(asm, value); + } if (is(NULL_CHECK, flags)) { asm.nop(1); asm.mark(MARK_IMPLICIT_NULL); } - if (kind == CiKind.Object) { - verifyPointer(asm, value); - } asm.pstore(kind, object, fieldOffset, value, is(NULL_CHECK, flags)); if (is(WRITE_BARRIER, flags)) { XirOperand temp = asm.createTemp("temp", CiKind.Word); diff -r 30e1f67703da -r 5571b97fc1ec c1x4hotspotsrc/hotspot/hotspot jtt.launch --- a/c1x4hotspotsrc/hotspot/hotspot jtt.launch Fri Nov 26 13:52:15 2010 +0100 +++ b/c1x4hotspotsrc/hotspot/hotspot jtt.launch Fri Nov 26 19:45:05 2010 +0100 @@ -1,7 +1,20 @@ + + + + + + + + + + + + + diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciEnv.cpp --- a/src/share/vm/ci/ciEnv.cpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciEnv.cpp Fri Nov 26 19:45:05 2010 +0100 @@ -165,6 +165,7 @@ } ciEnv::~ciEnv() { + _factory->cleanup(); CompilerThread* current_thread = CompilerThread::current(); current_thread->set_env(NULL); } diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciInstanceKlass.cpp --- a/src/share/vm/ci/ciInstanceKlass.cpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciInstanceKlass.cpp Fri Nov 26 19:45:05 2010 +0100 @@ -66,7 +66,7 @@ Handle h_protection_domain(thread, ik->protection_domain()); _loader = JNIHandles::make_global(h_loader); _protection_domain = JNIHandles::make_global(h_protection_domain); - _is_shared = true; + _is_shared = !ciObjectFactory::is_initialized(); } // Lazy fields get filled in only upon request. diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciInstanceKlass.hpp --- a/src/share/vm/ci/ciInstanceKlass.hpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciInstanceKlass.hpp Fri Nov 26 19:45:05 2010 +0100 @@ -63,6 +63,19 @@ GrowableArray* _non_static_fields; +public: + virtual void cleanup() { + ciObject::cleanup(); + if (!_is_shared) { + if (JNIHandles::is_global_handle(_loader)) { + JNIHandles::destroy_global(_loader); + } + if (JNIHandles::is_global_handle(_protection_domain)) { + JNIHandles::destroy_global(_protection_domain); + } + } + } + protected: ciInstanceKlass(KlassHandle h_k); ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain); diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciObject.cpp --- a/src/share/vm/ci/ciObject.cpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciObject.cpp Fri Nov 26 19:45:05 2010 +0100 @@ -48,14 +48,20 @@ // ciObject::ciObject ciObject::ciObject(oop o) { ASSERT_IN_VM; - if (ciObjectFactory::is_initialized() && !UseC1X) { - _handle = JNIHandles::make_local(o); + if (ciObjectFactory::is_initialized()) { + if (UseC1X) { + _handle = JNIHandles::make_global(o); + _temp_global = true; + } else { + _handle = JNIHandles::make_local(o); + } } else { _handle = JNIHandles::make_global(o); } _klass = NULL; _ident = 0; init_flags_from(o); + _temp_global = false; } // ------------------------------------------------------------------ @@ -63,14 +69,20 @@ // ciObject::ciObject(Handle h) { ASSERT_IN_VM; - if (ciObjectFactory::is_initialized() && !UseC1X) { - _handle = JNIHandles::make_local(h()); + if (ciObjectFactory::is_initialized()) { + if (UseC1X) { + _handle = JNIHandles::make_global(h); + _temp_global = true; + } else { + _handle = JNIHandles::make_local(h()); + } } else { _handle = JNIHandles::make_global(h); } _klass = NULL; _ident = 0; init_flags_from(h()); + _temp_global = false; } // ------------------------------------------------------------------ @@ -84,6 +96,7 @@ _handle = NULL; _klass = klass; _ident = 0; + _temp_global = false; } // ------------------------------------------------------------------ @@ -95,6 +108,7 @@ _handle = NULL; _klass = NULL; _ident = 0; + _temp_global = false; } // ------------------------------------------------------------------ diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciObject.hpp --- a/src/share/vm/ci/ciObject.hpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciObject.hpp Fri Nov 26 19:45:05 2010 +0100 @@ -50,6 +50,7 @@ jobject _handle; ciKlass* _klass; uint _ident; + bool _temp_global; enum { FLAG_BITS = 2 }; enum { @@ -63,6 +64,11 @@ ciObject(ciKlass* klass); public: + virtual void cleanup() { + if (_temp_global && _handle != NULL && JNIHandles::is_global_handle(_handle)) { + JNIHandles::destroy_global(_handle); + } + } jobject handle() const { return _handle; } // Get the VM oop that this object holds. oop get_oop() const { diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciObjectFactory.cpp --- a/src/share/vm/ci/ciObjectFactory.cpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciObjectFactory.cpp Fri Nov 26 19:45:05 2010 +0100 @@ -74,6 +74,14 @@ new (arena) GrowableArray(arena, 8, 0, NULL); } +void ciObjectFactory::cleanup() { + int start = 0; + if (_shared_ci_objects != NULL) start = _shared_ci_objects->length(); + for (int i = start; i < _ci_objects->length(); ++i) { + _ci_objects->at(i)->cleanup(); + } +} + // ------------------------------------------------------------------ // ciObjectFactory::ciObjectFactory void ciObjectFactory::initialize() { diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/ci/ciObjectFactory.hpp --- a/src/share/vm/ci/ciObjectFactory.hpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/ci/ciObjectFactory.hpp Fri Nov 26 19:45:05 2010 +0100 @@ -81,6 +81,7 @@ ciObjectFactory(Arena* arena, int expected_size); + void cleanup(); // Get the ciObject corresponding to some oop. ciObject* get(oop key); diff -r 30e1f67703da -r 5571b97fc1ec src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp Fri Nov 26 13:52:15 2010 +0100 +++ b/src/share/vm/compiler/compileBroker.cpp Fri Nov 26 19:45:05 2010 +0100 @@ -1616,7 +1616,7 @@ } // (tw) Check if we may do this? - //NoHandleMark nhm; + // NoHandleMark nhm; ThreadToNativeFromVM ttn(thread); ciEnv ci_env(task, system_dictionary_modification_counter);