From a6f03fa1e45af37b75d17bb948af82ded960fe0c Mon Sep 17 00:00:00 2001 From: mchung Date: Wed, 25 Nov 2009 08:37:04 -0800 Subject: 6888880: JKernel VM to inject the sun.jkernel.DownloadManager as a boot classloader hook Summary: Call sun.jkernel.DownloadManager.setBootClassLoaderHook during the kernel VM initialization Reviewed-by: alanb, coleenp, acorn --- src/share/vm/classfile/vmSymbols.hpp | 1 + src/share/vm/runtime/thread.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp index bb9f3076a..fdc8786e5 100644 --- a/src/share/vm/classfile/vmSymbols.hpp +++ b/src/share/vm/classfile/vmSymbols.hpp @@ -104,6 +104,7 @@ template(java_lang_AssertionStatusDirectives, "java/lang/AssertionStatusDirectives") \ template(sun_jkernel_DownloadManager, "sun/jkernel/DownloadManager") \ template(getBootClassPathEntryForClass_name, "getBootClassPathEntryForClass") \ + template(setBootClassLoaderHook_name, "setBootClassLoaderHook") \ \ /* class file format tags */ \ template(tag_source_file, "SourceFile") \ diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp index 38e3ac438..5b2b90ded 100644 --- a/src/share/vm/runtime/thread.cpp +++ b/src/share/vm/runtime/thread.cpp @@ -884,6 +884,22 @@ static void call_initializeSystemClass(TRAPS) { vmSymbolHandles::void_method_signature(), CHECK); } +#ifdef KERNEL +static void set_jkernel_boot_classloader_hook(TRAPS) { + klassOop k = SystemDictionary::sun_jkernel_DownloadManager_klass(); + instanceKlassHandle klass (THREAD, k); + + if (k == NULL) { + // sun.jkernel.DownloadManager may not present in the JDK; just return + return; + } + + JavaValue result(T_VOID); + JavaCalls::call_static(&result, klass, vmSymbolHandles::setBootClassLoaderHook_name(), + vmSymbolHandles::void_method_signature(), CHECK); +} +#endif // KERNEL + static void reset_vm_info_property(TRAPS) { // the vm info string ResourceMark rm(THREAD); @@ -3102,6 +3118,12 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); } +#ifdef KERNEL + if (JDK_Version::is_gte_jdk17x_version()) { + set_jkernel_boot_classloader_hook(THREAD); + } +#endif // KERNEL + #ifndef SERIALGC // Support for ConcurrentMarkSweep. This should be cleaned up // and better encapsulated. The ugly nested if test would go away -- cgit v1.2.3 From 181ad72743b56395f1399798b9295916c5a3ba5e Mon Sep 17 00:00:00 2001 From: dholmes Date: Tue, 1 Dec 2009 22:29:02 -0500 Subject: 6822370: ReentrantReadWriteLock: threads hung when there are no threads holding onto the lock (Netra x4450) Summary: This day one bug is caused by missing memory barriers in various Parker::park() paths that can result in lost wakeups and hangs. Reviewed-by: dice, acorn --- src/os/linux/vm/os_linux.cpp | 3 +++ src/os/solaris/vm/os_solaris.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index 281e81c26..6aa3ebc0a 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -4683,6 +4683,7 @@ void Parker::park(bool isAbsolute, jlong time) { // Return immediately if a permit is available. if (_counter > 0) { _counter = 0 ; + OrderAccess::fence(); return ; } @@ -4725,6 +4726,7 @@ void Parker::park(bool isAbsolute, jlong time) { _counter = 0; status = pthread_mutex_unlock(_mutex); assert (status == 0, "invariant") ; + OrderAccess::fence(); return; } @@ -4765,6 +4767,7 @@ void Parker::park(bool isAbsolute, jlong time) { jt->java_suspend_self(); } + OrderAccess::fence(); } void Parker::unpark() { diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 13abbf9d4..b85bcef8c 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -5803,6 +5803,7 @@ void Parker::park(bool isAbsolute, jlong time) { // Return immediately if a permit is available. if (_counter > 0) { _counter = 0 ; + OrderAccess::fence(); return ; } @@ -5846,6 +5847,7 @@ void Parker::park(bool isAbsolute, jlong time) { _counter = 0; status = os::Solaris::mutex_unlock(_mutex); assert (status == 0, "invariant") ; + OrderAccess::fence(); return; } @@ -5892,6 +5894,7 @@ void Parker::park(bool isAbsolute, jlong time) { jt->java_suspend_self(); } + OrderAccess::fence(); } void Parker::unpark() { -- cgit v1.2.3 From 3f4e56d011d259da3ef65c59b720193ec9284a15 Mon Sep 17 00:00:00 2001 From: minqi Date: Fri, 11 Dec 2009 11:09:49 -0800 Subject: 6361589: Print out stack trace for target thread of GC crash Summary: If GC crashed with java thread involved, print out the java stack trace in error report Reviewed-by: never, ysr, coleenp, dholmes --- src/share/vm/runtime/frame.cpp | 16 +++++++++++++--- src/share/vm/runtime/globals.hpp | 3 +++ src/share/vm/runtime/thread.cpp | 24 ++++++++++++++++++++++++ src/share/vm/runtime/thread.hpp | 14 +++++++++++++- src/share/vm/runtime/vmStructs.cpp | 1 + src/share/vm/runtime/vmThread.cpp | 4 ++-- src/share/vm/runtime/vmThread.hpp | 4 +--- src/share/vm/utilities/vmError.cpp | 17 +++++++++++++++++ 8 files changed, 74 insertions(+), 9 deletions(-) diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp index 4ce96408c..6f87873bf 100644 --- a/src/share/vm/runtime/frame.cpp +++ b/src/share/vm/runtime/frame.cpp @@ -1190,9 +1190,19 @@ void frame::oops_entry_do(OopClosure* f, const RegisterMap* map) { void frame::oops_do_internal(OopClosure* f, CodeBlobClosure* cf, RegisterMap* map, bool use_interpreter_oop_map_cache) { - if (is_interpreted_frame()) { oops_interpreted_do(f, map, use_interpreter_oop_map_cache); - } else if (is_entry_frame()) { oops_entry_do (f, map); - } else if (CodeCache::contains(pc())) { oops_code_blob_do (f, cf, map); +#ifndef PRODUCT + // simulate GC crash here to dump java thread in error report + if (CrashGCForDumpingJavaThread) { + char *t = NULL; + *t = 'c'; + } +#endif + if (is_interpreted_frame()) { + oops_interpreted_do(f, map, use_interpreter_oop_map_cache); + } else if (is_entry_frame()) { + oops_entry_do(f, map); + } else if (CodeCache::contains(pc())) { + oops_code_blob_do(f, cf, map); } else { ShouldNotReachHere(); } diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index b894aac43..62dceadc2 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -2554,6 +2554,9 @@ class CommandLineFlags { "Include miscellaneous runtime verifications in nmethod code; " \ "default off because it disturbs nmethod size heuristics") \ \ + notproduct(bool, CrashGCForDumpingJavaThread, false, \ + "Manually make GC thread crash then dump java stack trace; " \ + "Test only") \ \ /* compilation */ \ product(bool, UseCompiler, true, \ diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp index 5b2b90ded..858c09f04 100644 --- a/src/share/vm/runtime/thread.cpp +++ b/src/share/vm/runtime/thread.cpp @@ -991,6 +991,7 @@ void JavaThread::allocate_threadObj(Handle thread_group, char* thread_name, bool // uniquely named instances should derive from this. NamedThread::NamedThread() : Thread() { _name = NULL; + _processed_thread = NULL; } NamedThread::~NamedThread() { @@ -2333,6 +2334,27 @@ void JavaThread::gc_prologue() { frames_do(frame_gc_prologue); } +// If the caller is a NamedThread, then remember, in the current scope, +// the given JavaThread in its _processed_thread field. +class RememberProcessedThread: public StackObj { + NamedThread* _cur_thr; +public: + RememberProcessedThread(JavaThread* jthr) { + Thread* thread = Thread::current(); + if (thread->is_Named_thread()) { + _cur_thr = (NamedThread *)thread; + _cur_thr->set_processed_thread(jthr); + } else { + _cur_thr = NULL; + } + } + + ~RememberProcessedThread() { + if (_cur_thr) { + _cur_thr->set_processed_thread(NULL); + } + } +}; void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) { // Flush deferred store-barriers, if any, associated with @@ -2349,6 +2371,8 @@ void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) { (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!"); if (has_last_Java_frame()) { + // Record JavaThread to GC thread + RememberProcessedThread rpt(this); // Traverse the privileged stack if (_privileged_stack_top != NULL) { diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp index cb4d6168a..e0ea0be55 100644 --- a/src/share/vm/runtime/thread.hpp +++ b/src/share/vm/runtime/thread.hpp @@ -48,7 +48,12 @@ class IdealGraphPrinter; // Class hierarchy // - Thread -// - VMThread +// - NamedThread +// - VMThread +// - ConcurrentGCThread +// - WorkerThread +// - GangWorker +// - GCTaskThread // - JavaThread // - WatcherThread @@ -249,6 +254,7 @@ class Thread: public ThreadShadow { virtual bool is_GC_task_thread() const { return false; } virtual bool is_Watcher_thread() const { return false; } virtual bool is_ConcurrentGC_thread() const { return false; } + virtual bool is_Named_thread() const { return false; } virtual char* name() const { return (char*)"Unknown thread"; } @@ -568,12 +574,18 @@ class NamedThread: public Thread { }; private: char* _name; + // log JavaThread being processed by oops_do + JavaThread* _processed_thread; + public: NamedThread(); ~NamedThread(); // May only be called once per thread. void set_name(const char* format, ...); + virtual bool is_Named_thread() const { return true; } virtual char* name() const { return _name == NULL ? (char*)"Unknown Thread" : _name; } + JavaThread *processed_thread() { return _processed_thread; } + void set_processed_thread(JavaThread *thread) { _processed_thread = thread; } }; // Worker threads are named and have an id of an assigned work. diff --git a/src/share/vm/runtime/vmStructs.cpp b/src/share/vm/runtime/vmStructs.cpp index bbff61b47..3e21d0d4b 100644 --- a/src/share/vm/runtime/vmStructs.cpp +++ b/src/share/vm/runtime/vmStructs.cpp @@ -666,6 +666,7 @@ static inline uint64_t cast_uint64_t(size_t x) nonstatic_field(Thread, _current_pending_monitor_is_from_java, bool) \ nonstatic_field(Thread, _current_waiting_monitor, ObjectMonitor*) \ nonstatic_field(NamedThread, _name, char*) \ + nonstatic_field(NamedThread, _processed_thread, JavaThread*) \ nonstatic_field(JavaThread, _next, JavaThread*) \ nonstatic_field(JavaThread, _threadObj, oop) \ nonstatic_field(JavaThread, _anchor, JavaFrameAnchor) \ diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp index b54f62515..26dad9a68 100644 --- a/src/share/vm/runtime/vmThread.cpp +++ b/src/share/vm/runtime/vmThread.cpp @@ -204,8 +204,8 @@ void VMThread::create() { } -VMThread::VMThread() : Thread() { - // nothing to do +VMThread::VMThread() : NamedThread() { + set_name("VM Thread"); } void VMThread::destroy() { diff --git a/src/share/vm/runtime/vmThread.hpp b/src/share/vm/runtime/vmThread.hpp index 7acf84a70..daa705138 100644 --- a/src/share/vm/runtime/vmThread.hpp +++ b/src/share/vm/runtime/vmThread.hpp @@ -83,7 +83,7 @@ class VMOperationQueue : public CHeapObj { // like scavenge, garbage_collect etc. // -class VMThread: public Thread { +class VMThread: public NamedThread { private: static ThreadPriority _current_priority; @@ -101,8 +101,6 @@ class VMThread: public Thread { bool is_VM_thread() const { return true; } bool is_GC_thread() const { return true; } - char* name() const { return (char*)"VM Thread"; } - // The ever running loop for the VMThread void loop(); diff --git a/src/share/vm/utilities/vmError.cpp b/src/share/vm/utilities/vmError.cpp index 2a2ddf83a..b758d8e9f 100644 --- a/src/share/vm/utilities/vmError.cpp +++ b/src/share/vm/utilities/vmError.cpp @@ -502,6 +502,23 @@ void VMError::report(outputStream* st) { #endif // ZERO } + STEP(135, "(printing target Java thread stack)" ) + + // printing Java thread stack trace if it is involved in GC crash + if (_verbose && (_thread->is_Named_thread())) { + JavaThread* jt = ((NamedThread *)_thread)->processed_thread(); + if (jt != NULL) { + st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id()); + if (jt->has_last_Java_frame()) { + st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)"); + for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) { + sfs.current()->print_on_error(st, buf, sizeof(buf), true); + st->cr(); + } + } + } + } + STEP(140, "(printing VM operation)" ) if (_verbose && _thread && _thread->is_VM_thread()) { -- cgit v1.2.3 From 07d1c3bd577eab55d047bffbb4ba99c528976797 Mon Sep 17 00:00:00 2001 From: dcubed Date: Mon, 14 Dec 2009 09:51:09 -0700 Subject: 6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check") Summary: Return error on invalid JVMTI_PHASE instead of asserting. Reviewed-by: dholmes, ohair --- src/share/vm/prims/jvmtiEnv.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp index a19c48972..77d63520d 100644 --- a/src/share/vm/prims/jvmtiEnv.cpp +++ b/src/share/vm/prims/jvmtiEnv.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -408,8 +408,10 @@ JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) { if (phase == JVMTI_PHASE_ONLOAD) { Arguments::append_sysclasspath(segment); return JVMTI_ERROR_NONE; - } else { - assert(phase == JVMTI_PHASE_LIVE, "sanity check"); + } else if (phase == JVMTI_PHASE_LIVE) { + // The phase is checked by the wrapper that called this function, + // but this thread could be racing with the thread that is + // terminating the VM so we check one more time. // create the zip entry ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment); @@ -430,6 +432,8 @@ JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) { } ClassLoader::add_to_list(zip_entry); return JVMTI_ERROR_NONE; + } else { + return JVMTI_ERROR_WRONG_PHASE; } } /* end AddToBootstrapClassLoaderSearch */ @@ -448,11 +452,12 @@ JvmtiEnv::AddToSystemClassLoaderSearch(const char* segment) { } } return JVMTI_ERROR_NONE; - } else { + } else if (phase == JVMTI_PHASE_LIVE) { + // The phase is checked by the wrapper that called this function, + // but this thread could be racing with the thread that is + // terminating the VM so we check one more time. HandleMark hm; - assert(phase == JVMTI_PHASE_LIVE, "sanity check"); - // create the zip entry (which will open the zip file and hence // check that the segment is indeed a zip file). ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment); @@ -501,6 +506,8 @@ JvmtiEnv::AddToSystemClassLoaderSearch(const char* segment) { } return JVMTI_ERROR_NONE; + } else { + return JVMTI_ERROR_WRONG_PHASE; } } /* end AddToSystemClassLoaderSearch */ -- cgit v1.2.3 From 0fc4275f8dac250ede9a0a82ff235ebe24e24dde Mon Sep 17 00:00:00 2001 From: dcubed Date: Mon, 14 Dec 2009 10:05:36 -0700 Subject: 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14 Summary: If a JVMTI agent asks for version 1.0, then it should get version 1.0 semantics. Reviewed-by: dholmes, ohair --- src/share/vm/prims/jvmtiEnv.cpp | 19 ++++++++++++++++--- src/share/vm/prims/jvmtiEnvBase.cpp | 23 +++++++++++++++++++++-- src/share/vm/prims/jvmtiEnvBase.hpp | 8 ++++++-- src/share/vm/prims/jvmtiExport.cpp | 35 ++++++++++++++++++++++++++++++++--- src/share/vm/prims/jvmtiExport.hpp | 4 +++- src/share/vm/prims/jvmtiHpp.xsl | 6 +++--- 6 files changed, 81 insertions(+), 14 deletions(-) diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp index 77d63520d..3de748f21 100644 --- a/src/share/vm/prims/jvmtiEnv.cpp +++ b/src/share/vm/prims/jvmtiEnv.cpp @@ -32,15 +32,15 @@ // FIXLATER: hook into JvmtiTrace #define TraceJVMTICalls false -JvmtiEnv::JvmtiEnv() : JvmtiEnvBase() { +JvmtiEnv::JvmtiEnv(jint version) : JvmtiEnvBase(version) { } JvmtiEnv::~JvmtiEnv() { } JvmtiEnv* -JvmtiEnv::create_a_jvmti() { - return new JvmtiEnv(); +JvmtiEnv::create_a_jvmti(jint version) { + return new JvmtiEnv(version); } // VM operation class to copy jni function table at safepoint. @@ -408,6 +408,11 @@ JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) { if (phase == JVMTI_PHASE_ONLOAD) { Arguments::append_sysclasspath(segment); return JVMTI_ERROR_NONE; + } else if (use_version_1_0_semantics()) { + // This JvmtiEnv requested version 1.0 semantics and this function + // is only allowed in the ONLOAD phase in version 1.0 so we need to + // return an error here. + return JVMTI_ERROR_WRONG_PHASE; } else if (phase == JVMTI_PHASE_LIVE) { // The phase is checked by the wrapper that called this function, // but this thread could be racing with the thread that is @@ -2857,6 +2862,14 @@ JvmtiEnv::IsMethodSynthetic(methodOop method_oop, jboolean* is_synthetic_ptr) { // is_obsolete_ptr - pre-checked for NULL jvmtiError JvmtiEnv::IsMethodObsolete(methodOop method_oop, jboolean* is_obsolete_ptr) { + if (use_version_1_0_semantics() && + get_capabilities()->can_redefine_classes == 0) { + // This JvmtiEnv requested version 1.0 semantics and this function + // requires the can_redefine_classes capability in version 1.0 so + // we need to return an error here. + return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; + } + if (method_oop == NULL || method_oop->is_obsolete()) { *is_obsolete_ptr = true; } else { diff --git a/src/share/vm/prims/jvmtiEnvBase.cpp b/src/share/vm/prims/jvmtiEnvBase.cpp index 3152e91c3..f7a37a90a 100644 --- a/src/share/vm/prims/jvmtiEnvBase.cpp +++ b/src/share/vm/prims/jvmtiEnvBase.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -94,7 +94,26 @@ JvmtiEnvBase::initialize() { } -JvmtiEnvBase::JvmtiEnvBase() : _env_event_enable() { +bool +JvmtiEnvBase::use_version_1_0_semantics() { + int major, minor, micro; + + JvmtiExport::decode_version_values(_version, &major, &minor, µ); + return major == 1 && minor == 0; // micro version doesn't matter here +} + + +bool +JvmtiEnvBase::use_version_1_1_semantics() { + int major, minor, micro; + + JvmtiExport::decode_version_values(_version, &major, &minor, µ); + return major == 1 && minor == 1; // micro version doesn't matter here +} + + +JvmtiEnvBase::JvmtiEnvBase(jint version) : _env_event_enable() { + _version = version; _env_local_storage = NULL; _tag_map = NULL; _native_method_prefix_count = 0; diff --git a/src/share/vm/prims/jvmtiEnvBase.hpp b/src/share/vm/prims/jvmtiEnvBase.hpp index 477725ffe..d2f3de552 100644 --- a/src/share/vm/prims/jvmtiEnvBase.hpp +++ b/src/share/vm/prims/jvmtiEnvBase.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -76,6 +76,7 @@ class JvmtiEnvBase : public CHeapObj { jvmtiEnv _jvmti_external; jint _magic; + jint _version; // version value passed to JNI GetEnv() JvmtiEnvBase* _next; bool _is_retransformable; const void *_env_local_storage; // per env agent allocated data. @@ -91,7 +92,7 @@ class JvmtiEnvBase : public CHeapObj { int _native_method_prefix_count; protected: - JvmtiEnvBase(); + JvmtiEnvBase(jint version); ~JvmtiEnvBase(); void dispose(); void env_dispose(); @@ -122,6 +123,9 @@ class JvmtiEnvBase : public CHeapObj { bool is_valid() { return _magic == JVMTI_MAGIC; } + bool use_version_1_0_semantics(); // agent asked for version 1.0 + bool use_version_1_1_semantics(); // agent asked for version 1.1 + bool is_retransformable() { return _is_retransformable; } static ByteSize jvmti_external_offset() { diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp index e51e5b3d4..cbdd7234a 100644 --- a/src/share/vm/prims/jvmtiExport.cpp +++ b/src/share/vm/prims/jvmtiExport.cpp @@ -319,7 +319,27 @@ address JvmtiExport::get_field_modification_count_addr() { jint JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { - /* To Do: add version checks */ + // The JVMTI_VERSION_INTERFACE_JVMTI part of the version number + // has already been validated in JNI GetEnv(). + int major, minor, micro; + + // micro version doesn't matter here (yet?) + decode_version_values(version, &major, &minor, µ); + switch (major) { + case 1: + switch (minor) { + case 0: // version 1.0. is recognized + case 1: // version 1.1. is recognized + break; + + default: + return JNI_EVERSION; // unsupported minor version number + } + break; + + default: + return JNI_EVERSION; // unsupported major version number + } if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) { JavaThread* current_thread = (JavaThread*) ThreadLocalStorage::thread(); @@ -328,13 +348,13 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { __ENTRY(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread) debug_only(VMNativeEntryWrapper __vew;) - JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(); + JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version); *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv* return JNI_OK; } else if (JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) { // not live, no thread to transition - JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(); + JvmtiEnv *jvmti_env = JvmtiEnv::create_a_jvmti(version); *penv = jvmti_env->jvmti_external(); // actual type is jvmtiEnv* -- not to be confused with JvmtiEnv* return JNI_OK; @@ -345,6 +365,15 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { } } + +void +JvmtiExport::decode_version_values(jint version, int * major, int * minor, + int * micro) { + *major = (version & JVMTI_VERSION_MASK_MAJOR) >> JVMTI_VERSION_SHIFT_MAJOR; + *minor = (version & JVMTI_VERSION_MASK_MINOR) >> JVMTI_VERSION_SHIFT_MINOR; + *micro = (version & JVMTI_VERSION_MASK_MICRO) >> JVMTI_VERSION_SHIFT_MICRO; +} + void JvmtiExport::enter_primordial_phase() { JvmtiEnvBase::set_phase(JVMTI_PHASE_PRIMORDIAL); } diff --git a/src/share/vm/prims/jvmtiExport.hpp b/src/share/vm/prims/jvmtiExport.hpp index 54a9416f4..20214aecf 100644 --- a/src/share/vm/prims/jvmtiExport.hpp +++ b/src/share/vm/prims/jvmtiExport.hpp @@ -1,5 +1,5 @@ /* - * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -236,6 +236,8 @@ class JvmtiExport : public AllStatic { static bool is_jvmti_version(jint version) { return (version & JVMTI_VERSION_MASK) == JVMTI_VERSION_VALUE; } static bool is_jvmdi_version(jint version) { return (version & JVMTI_VERSION_MASK) == JVMDI_VERSION_VALUE; } static jint get_jvmti_interface(JavaVM *jvm, void **penv, jint version); + static void decode_version_values(jint version, int * major, int * minor, + int * micro); // single stepping management methods static void at_single_stepping_point(JavaThread *thread, methodOop method, address location) KERNEL_RETURN; diff --git a/src/share/vm/prims/jvmtiHpp.xsl b/src/share/vm/prims/jvmtiHpp.xsl index 3b3b23e90..e5dd49ffc 100644 --- a/src/share/vm/prims/jvmtiHpp.xsl +++ b/src/share/vm/prims/jvmtiHpp.xsl @@ -1,6 +1,6 @@