Thu, 18 Jul 2013 12:05:32 -0700
Merge
src/share/vm/services/memTracker.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/make/windows/makefiles/compile.make Thu Jul 18 09:35:02 2013 -0700 1.2 +++ b/make/windows/makefiles/compile.make Thu Jul 18 12:05:32 2013 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 # 1.5 -# Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 +# Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 # 1.9 # This code is free software; you can redistribute it and/or modify it 1.10 @@ -110,6 +110,7 @@ 1.11 # 1400 is for VS2005 1.12 # 1500 is for VS2008 1.13 # 1600 is for VS2010 1.14 +# 1700 is for VS2012 1.15 # Do not confuse this MSC_VER with the predefined macro _MSC_VER that the 1.16 # compiler provides, when MSC_VER==1399, _MSC_VER will be 1400. 1.17 # Normally they are the same, but a pre-release of the VS2005 compilers 1.18 @@ -142,6 +143,9 @@ 1.19 !if "$(MSC_VER)" == "1600" 1.20 COMPILER_NAME=VS2010 1.21 !endif 1.22 +!if "$(MSC_VER)" == "1700" 1.23 +COMPILER_NAME=VS2012 1.24 +!endif 1.25 !endif 1.26 1.27 # By default, we do not want to use the debug version of the msvcrt.dll file 1.28 @@ -151,9 +155,13 @@ 1.29 MS_RUNTIME_OPTION = /MTd /D "_DEBUG" 1.30 !endif 1.31 1.32 +# VS2012 and later won't work with: 1.33 +# /D _STATIC_CPPLIB /D _DISABLE_DEPRECATE_STATIC_CPPLIB 1.34 +!if "$(MSC_VER)" < "1700" 1.35 # Always add the _STATIC_CPPLIB flag 1.36 STATIC_CPPLIB_OPTION = /D _STATIC_CPPLIB /D _DISABLE_DEPRECATE_STATIC_CPPLIB 1.37 MS_RUNTIME_OPTION = $(MS_RUNTIME_OPTION) $(STATIC_CPPLIB_OPTION) 1.38 +!endif 1.39 CXX_FLAGS=$(CXX_FLAGS) $(MS_RUNTIME_OPTION) 1.40 1.41 # How /GX option is spelled 1.42 @@ -221,6 +229,22 @@ 1.43 !endif 1.44 !endif 1.45 1.46 +!if "$(COMPILER_NAME)" == "VS2012" 1.47 +PRODUCT_OPT_OPTION = /O2 /Oy- 1.48 +FASTDEBUG_OPT_OPTION = /O2 /Oy- 1.49 +DEBUG_OPT_OPTION = /Od 1.50 +GX_OPTION = /EHsc 1.51 +LD_FLAGS = /manifest $(LD_FLAGS) 1.52 +# Manifest Tool - used in VS2005 and later to adjust manifests stored 1.53 +# as resources inside build artifacts. 1.54 +!if "x$(MT)" == "x" 1.55 +MT=mt.exe 1.56 +!endif 1.57 +!if "$(BUILDARCH)" == "i486" 1.58 +LD_FLAGS = /SAFESEH $(LD_FLAGS) 1.59 +!endif 1.60 +!endif 1.61 + 1.62 # If NO_OPTIMIZATIONS is defined in the environment, turn everything off 1.63 !ifdef NO_OPTIMIZATIONS 1.64 PRODUCT_OPT_OPTION = $(DEBUG_OPT_OPTION)
2.1 --- a/make/windows/makefiles/sanity.make Thu Jul 18 09:35:02 2013 -0700 2.2 +++ b/make/windows/makefiles/sanity.make Thu Jul 18 12:05:32 2013 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 # 2.5 -# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 2.6 +# Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 2.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 # 2.9 # This code is free software; you can redistribute it and/or modify it 2.10 @@ -27,9 +27,9 @@ 2.11 all: checkCL checkLink 2.12 2.13 checkCL: 2.14 - @ if "$(MSC_VER)" NEQ "1310" if "$(MSC_VER)" NEQ "1399" if "$(MSC_VER)" NEQ "1400" if "$(MSC_VER)" NEQ "1500" if "$(MSC_VER)" NEQ "1600" \ 2.15 + @ if "$(MSC_VER)" NEQ "1310" if "$(MSC_VER)" NEQ "1399" if "$(MSC_VER)" NEQ "1400" if "$(MSC_VER)" NEQ "1500" if "$(MSC_VER)" NEQ "1600" if "$(MSC_VER)" NEQ "1700" \ 2.16 echo *** WARNING *** unrecognized cl.exe version $(MSC_VER) ($(RAW_MSC_VER)). Use FORCE_MSC_VER to override automatic detection. 2.17 2.18 checkLink: 2.19 - @ if "$(LD_VER)" NEQ "710" if "$(LD_VER)" NEQ "800" if "$(LD_VER)" NEQ "900" if "$(LD_VER)" NEQ "1000" \ 2.20 + @ if "$(LD_VER)" NEQ "710" if "$(LD_VER)" NEQ "800" if "$(LD_VER)" NEQ "900" if "$(LD_VER)" NEQ "1000" if "$(LD_VER)" NEQ "1100" \ 2.21 echo *** WARNING *** unrecognized link.exe version $(LD_VER) ($(RAW_LD_VER)). Use FORCE_LD_VER to override automatic detection.
3.1 --- a/make/windows/makefiles/vm.make Thu Jul 18 09:35:02 2013 -0700 3.2 +++ b/make/windows/makefiles/vm.make Thu Jul 18 12:05:32 2013 -0700 3.3 @@ -132,6 +132,10 @@ 3.4 3.5 !if "$(USE_PRECOMPILED_HEADER)" != "0" 3.6 CXX_USE_PCH=/Fp"vm.pch" /Yu"precompiled.hpp" 3.7 +!if "$(COMPILER_NAME)" == "VS2012" 3.8 +# VS2012 requires this object file to be listed: 3.9 +LD_FLAGS=$(LD_FLAGS) _build_pch_file.obj 3.10 +!endif 3.11 !else 3.12 CXX_USE_PCH=$(CXX_DONT_USE_PCH) 3.13 !endif
4.1 --- a/src/cpu/sparc/vm/frame_sparc.inline.hpp Thu Jul 18 09:35:02 2013 -0700 4.2 +++ b/src/cpu/sparc/vm/frame_sparc.inline.hpp Thu Jul 18 12:05:32 2013 -0700 4.3 @@ -240,10 +240,10 @@ 4.4 #endif // CC_INTERP 4.5 4.6 4.7 -inline JavaCallWrapper* frame::entry_frame_call_wrapper() const { 4.8 +inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const { 4.9 // note: adjust this code if the link argument in StubGenerator::call_stub() changes! 4.10 const Argument link = Argument(0, false); 4.11 - return (JavaCallWrapper*)sp()[link.as_in().as_register()->sp_offset_in_saved_window()]; 4.12 + return (JavaCallWrapper**)&sp()[link.as_in().as_register()->sp_offset_in_saved_window()]; 4.13 } 4.14 4.15
5.1 --- a/src/cpu/x86/vm/frame_x86.inline.hpp Thu Jul 18 09:35:02 2013 -0700 5.2 +++ b/src/cpu/x86/vm/frame_x86.inline.hpp Thu Jul 18 12:05:32 2013 -0700 5.3 @@ -272,11 +272,10 @@ 5.4 5.5 // Entry frames 5.6 5.7 -inline JavaCallWrapper* frame::entry_frame_call_wrapper() const { 5.8 - return (JavaCallWrapper*)at(entry_frame_call_wrapper_offset); 5.9 +inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const { 5.10 + return (JavaCallWrapper**)addr_at(entry_frame_call_wrapper_offset); 5.11 } 5.12 5.13 - 5.14 // Compiled frames 5.15 5.16 inline int frame::local_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors) {
6.1 --- a/src/os/bsd/vm/attachListener_bsd.cpp Thu Jul 18 09:35:02 2013 -0700 6.2 +++ b/src/os/bsd/vm/attachListener_bsd.cpp Thu Jul 18 12:05:32 2013 -0700 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -437,6 +437,30 @@ 6.11 return op; 6.12 } 6.13 6.14 + 6.15 +// Performs initialization at vm startup 6.16 +// For BSD we remove any stale .java_pid file which could cause 6.17 +// an attaching process to think we are ready to receive on the 6.18 +// domain socket before we are properly initialized 6.19 + 6.20 +void AttachListener::vm_start() { 6.21 + char fn[UNIX_PATH_MAX]; 6.22 + struct stat64 st; 6.23 + int ret; 6.24 + 6.25 + int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d", 6.26 + os::get_temp_directory(), os::current_process_id()); 6.27 + assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow"); 6.28 + 6.29 + RESTARTABLE(::stat64(fn, &st), ret); 6.30 + if (ret == 0) { 6.31 + ret = ::unlink(fn); 6.32 + if (ret == -1) { 6.33 + debug_only(warning("failed to remove stale attach pid file at %s", fn)); 6.34 + } 6.35 + } 6.36 +} 6.37 + 6.38 int AttachListener::pd_init() { 6.39 JavaThread* thread = JavaThread::current(); 6.40 ThreadBlockInVM tbivm(thread);
7.1 --- a/src/os/linux/vm/attachListener_linux.cpp Thu Jul 18 09:35:02 2013 -0700 7.2 +++ b/src/os/linux/vm/attachListener_linux.cpp Thu Jul 18 12:05:32 2013 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -432,6 +432,30 @@ 7.11 return op; 7.12 } 7.13 7.14 + 7.15 +// Performs initialization at vm startup 7.16 +// For Linux we remove any stale .java_pid file which could cause 7.17 +// an attaching process to think we are ready to receive on the 7.18 +// domain socket before we are properly initialized 7.19 + 7.20 +void AttachListener::vm_start() { 7.21 + char fn[UNIX_PATH_MAX]; 7.22 + struct stat64 st; 7.23 + int ret; 7.24 + 7.25 + int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d", 7.26 + os::get_temp_directory(), os::current_process_id()); 7.27 + assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow"); 7.28 + 7.29 + RESTARTABLE(::stat64(fn, &st), ret); 7.30 + if (ret == 0) { 7.31 + ret = ::unlink(fn); 7.32 + if (ret == -1) { 7.33 + debug_only(warning("failed to remove stale attach pid file at %s", fn)); 7.34 + } 7.35 + } 7.36 +} 7.37 + 7.38 int AttachListener::pd_init() { 7.39 JavaThread* thread = JavaThread::current(); 7.40 ThreadBlockInVM tbivm(thread);
8.1 --- a/src/os/linux/vm/jsig.c Thu Jul 18 09:35:02 2013 -0700 8.2 +++ b/src/os/linux/vm/jsig.c Thu Jul 18 12:05:32 2013 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -107,7 +107,7 @@ 8.11 8.12 signal_lock(); 8.13 8.14 - sigused = (MASK(sig) & jvmsigs) != 0; 8.15 + sigused = (sig < MAXSIGNUM) && ((MASK(sig) & jvmsigs) != 0); 8.16 if (jvm_signal_installed && sigused) { 8.17 /* jvm has installed its signal handler for this signal. */ 8.18 /* Save the handler. Don't really install it. */ 8.19 @@ -116,7 +116,7 @@ 8.20 8.21 signal_unlock(); 8.22 return oldhandler; 8.23 - } else if (jvm_signal_installing) { 8.24 + } else if (sig < MAXSIGNUM && jvm_signal_installing) { 8.25 /* jvm is installing its signal handlers. Install the new 8.26 * handlers and save the old ones. jvm uses sigaction(). 8.27 * Leave the piece here just in case. */ 8.28 @@ -165,7 +165,7 @@ 8.29 8.30 signal_lock(); 8.31 8.32 - sigused = (MASK(sig) & jvmsigs) != 0; 8.33 + sigused = (sig < MAXSIGNUM) && ((MASK(sig) & jvmsigs) != 0); 8.34 if (jvm_signal_installed && sigused) { 8.35 /* jvm has installed its signal handler for this signal. */ 8.36 /* Save the handler. Don't really install it. */ 8.37 @@ -178,7 +178,7 @@ 8.38 8.39 signal_unlock(); 8.40 return 0; 8.41 - } else if (jvm_signal_installing) { 8.42 + } else if (sig < MAXSIGNUM && jvm_signal_installing) { 8.43 /* jvm is installing its signal handlers. Install the new 8.44 * handlers and save the old ones. */ 8.45 res = call_os_sigaction(sig, act, &oldAct);
9.1 --- a/src/os/solaris/vm/attachListener_solaris.cpp Thu Jul 18 09:35:02 2013 -0700 9.2 +++ b/src/os/solaris/vm/attachListener_solaris.cpp Thu Jul 18 12:05:32 2013 -0700 9.3 @@ -1,5 +1,5 @@ 9.4 /* 9.5 - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 9.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 9.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 * 9.9 * This code is free software; you can redistribute it and/or modify it 9.10 @@ -576,6 +576,30 @@ 9.11 return op; 9.12 } 9.13 9.14 + 9.15 +// Performs initialization at vm startup 9.16 +// For Solaris we remove any stale .java_pid file which could cause 9.17 +// an attaching process to think we are ready to receive a door_call 9.18 +// before we are properly initialized 9.19 + 9.20 +void AttachListener::vm_start() { 9.21 + char fn[PATH_MAX+1]; 9.22 + struct stat64 st; 9.23 + int ret; 9.24 + 9.25 + int n = snprintf(fn, sizeof(fn), "%s/.java_pid%d", 9.26 + os::get_temp_directory(), os::current_process_id()); 9.27 + assert(n < sizeof(fn), "java_pid file name buffer overflow"); 9.28 + 9.29 + RESTARTABLE(::stat64(fn, &st), ret); 9.30 + if (ret == 0) { 9.31 + ret = ::unlink(fn); 9.32 + if (ret == -1) { 9.33 + debug_only(warning("failed to remove stale attach pid file at %s", fn)); 9.34 + } 9.35 + } 9.36 +} 9.37 + 9.38 int AttachListener::pd_init() { 9.39 JavaThread* thread = JavaThread::current(); 9.40 ThreadBlockInVM tbivm(thread);
10.1 --- a/src/os/windows/vm/attachListener_windows.cpp Thu Jul 18 09:35:02 2013 -0700 10.2 +++ b/src/os/windows/vm/attachListener_windows.cpp Thu Jul 18 12:05:32 2013 -0700 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -358,6 +358,10 @@ 10.11 return op; 10.12 } 10.13 10.14 +void AttachListener::vm_start() { 10.15 + // nothing to do 10.16 +} 10.17 + 10.18 int AttachListener::pd_init() { 10.19 return Win32AttachListener::init(); 10.20 }
11.1 --- a/src/os_cpu/windows_x86/vm/unwind_windows_x86.hpp Thu Jul 18 09:35:02 2013 -0700 11.2 +++ b/src/os_cpu/windows_x86/vm/unwind_windows_x86.hpp Thu Jul 18 12:05:32 2013 -0700 11.3 @@ -1,5 +1,5 @@ 11.4 /* 11.5 - * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 11.6 + * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. 11.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.8 * 11.9 * This code is free software; you can redistribute it and/or modify it 11.10 @@ -29,10 +29,15 @@ 11.11 #ifdef AMD64 11.12 typedef unsigned char UBYTE; 11.13 11.14 +#if _MSC_VER < 1700 11.15 + 11.16 +/* Not needed for VS2012 compiler, comes from winnt.h. */ 11.17 #define UNW_FLAG_EHANDLER 0x01 11.18 #define UNW_FLAG_UHANDLER 0x02 11.19 #define UNW_FLAG_CHAININFO 0x04 11.20 11.21 +#endif 11.22 + 11.23 // This structure is used to define an UNWIND_INFO that 11.24 // only has an ExceptionHandler. There are no UnwindCodes 11.25 // declared. 11.26 @@ -59,6 +64,9 @@ 11.27 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION; 11.28 */ 11.29 11.30 +#if _MSC_VER < 1700 11.31 + 11.32 +/* Not needed for VS2012 compiler, comes from winnt.h. */ 11.33 typedef struct _DISPATCHER_CONTEXT { 11.34 ULONG64 ControlPc; 11.35 ULONG64 ImageBase; 11.36 @@ -71,6 +79,8 @@ 11.37 PVOID HandlerData; 11.38 } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT; 11.39 11.40 +#endif 11.41 + 11.42 #if _MSC_VER < 1500 11.43 11.44 /* Not needed for VS2008 compiler, comes from winnt.h. */
12.1 --- a/src/share/vm/classfile/classFileParser.cpp Thu Jul 18 09:35:02 2013 -0700 12.2 +++ b/src/share/vm/classfile/classFileParser.cpp Thu Jul 18 12:05:32 2013 -0700 12.3 @@ -3647,8 +3647,7 @@ 12.4 // If RedefineClasses() was used before the retransformable 12.5 // agent attached, then the cached class bytes may not be the 12.6 // original class bytes. 12.7 - unsigned char *cached_class_file_bytes = NULL; 12.8 - jint cached_class_file_length; 12.9 + JvmtiCachedClassFileData *cached_class_file = NULL; 12.10 Handle class_loader(THREAD, loader_data->class_loader()); 12.11 bool has_default_methods = false; 12.12 ResourceMark rm(THREAD); 12.13 @@ -3680,10 +3679,7 @@ 12.14 if (h_class_being_redefined != NULL) { 12.15 instanceKlassHandle ikh_class_being_redefined = 12.16 instanceKlassHandle(THREAD, (*h_class_being_redefined)()); 12.17 - cached_class_file_bytes = 12.18 - ikh_class_being_redefined->get_cached_class_file_bytes(); 12.19 - cached_class_file_length = 12.20 - ikh_class_being_redefined->get_cached_class_file_len(); 12.21 + cached_class_file = ikh_class_being_redefined->get_cached_class_file(); 12.22 } 12.23 } 12.24 12.25 @@ -3691,9 +3687,7 @@ 12.26 unsigned char* end_ptr = cfs->buffer() + cfs->length(); 12.27 12.28 JvmtiExport::post_class_file_load_hook(name, class_loader(), protection_domain, 12.29 - &ptr, &end_ptr, 12.30 - &cached_class_file_bytes, 12.31 - &cached_class_file_length); 12.32 + &ptr, &end_ptr, &cached_class_file); 12.33 12.34 if (ptr != cfs->buffer()) { 12.35 // JVMTI agent has modified class file data. 12.36 @@ -4011,10 +4005,9 @@ 12.37 } 12.38 } 12.39 12.40 - if (cached_class_file_bytes != NULL) { 12.41 + if (cached_class_file != NULL) { 12.42 // JVMTI: we have an InstanceKlass now, tell it about the cached bytes 12.43 - this_klass->set_cached_class_file(cached_class_file_bytes, 12.44 - cached_class_file_length); 12.45 + this_klass->set_cached_class_file(cached_class_file); 12.46 } 12.47 12.48 // Fill in field values obtained by parse_classfile_attributes
13.1 --- a/src/share/vm/memory/resourceArea.hpp Thu Jul 18 09:35:02 2013 -0700 13.2 +++ b/src/share/vm/memory/resourceArea.hpp Thu Jul 18 12:05:32 2013 -0700 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 13.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.8 * 13.9 * This code is free software; you can redistribute it and/or modify it 13.10 @@ -83,6 +83,10 @@ 13.11 Chunk *_chunk; // saved arena chunk 13.12 char *_hwm, *_max; 13.13 size_t _size_in_bytes; 13.14 +#ifdef ASSERT 13.15 + Thread* _thread; 13.16 + ResourceMark* _previous_resource_mark; 13.17 +#endif //ASSERT 13.18 13.19 void initialize(Thread *thread) { 13.20 _area = thread->resource_area(); 13.21 @@ -92,6 +96,11 @@ 13.22 _size_in_bytes = _area->size_in_bytes(); 13.23 debug_only(_area->_nesting++;) 13.24 assert( _area->_nesting > 0, "must stack allocate RMs" ); 13.25 +#ifdef ASSERT 13.26 + _thread = thread; 13.27 + _previous_resource_mark = thread->current_resource_mark(); 13.28 + thread->set_current_resource_mark(this); 13.29 +#endif // ASSERT 13.30 } 13.31 public: 13.32 13.33 @@ -111,6 +120,17 @@ 13.34 _size_in_bytes = r->_size_in_bytes; 13.35 debug_only(_area->_nesting++;) 13.36 assert( _area->_nesting > 0, "must stack allocate RMs" ); 13.37 +#ifdef ASSERT 13.38 + Thread* thread = ThreadLocalStorage::thread(); 13.39 + if (thread != NULL) { 13.40 + _thread = thread; 13.41 + _previous_resource_mark = thread->current_resource_mark(); 13.42 + thread->set_current_resource_mark(this); 13.43 + } else { 13.44 + _thread = NULL; 13.45 + _previous_resource_mark = NULL; 13.46 + } 13.47 +#endif // ASSERT 13.48 } 13.49 13.50 void reset_to_mark() { 13.51 @@ -137,6 +157,11 @@ 13.52 assert( _area->_nesting > 0, "must stack allocate RMs" ); 13.53 debug_only(_area->_nesting--;) 13.54 reset_to_mark(); 13.55 +#ifdef ASSERT 13.56 + if (_thread != NULL) { 13.57 + _thread->set_current_resource_mark(_previous_resource_mark); 13.58 + } 13.59 +#endif // ASSERT 13.60 } 13.61 13.62
14.1 --- a/src/share/vm/oops/cpCache.hpp Thu Jul 18 09:35:02 2013 -0700 14.2 +++ b/src/share/vm/oops/cpCache.hpp Thu Jul 18 12:05:32 2013 -0700 14.3 @@ -140,8 +140,15 @@ 14.4 _f1 = f1; 14.5 } 14.6 void release_set_f1(Metadata* f1); 14.7 - void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; } 14.8 - void set_f2_as_vfinal_method(Method* f2) { assert(_f2 == 0 || _f2 == (intptr_t) f2, "illegal field change"); assert(is_vfinal(), "flags must be set"); _f2 = (intptr_t) f2; } 14.9 + void set_f2(intx f2) { 14.10 + intx existing_f2 = _f2; // read once 14.11 + assert(existing_f2 == 0 || existing_f2 == f2, "illegal field change"); 14.12 + _f2 = f2; 14.13 + } 14.14 + void set_f2_as_vfinal_method(Method* f2) { 14.15 + assert(is_vfinal(), "flags must be set"); 14.16 + set_f2((intx)f2); 14.17 + } 14.18 int make_flags(TosState state, int option_bits, int field_index_or_method_params); 14.19 void set_flags(intx flags) { _flags = flags; } 14.20 bool init_flags_atomic(intx flags);
15.1 --- a/src/share/vm/oops/instanceKlass.cpp Thu Jul 18 09:35:02 2013 -0700 15.2 +++ b/src/share/vm/oops/instanceKlass.cpp Thu Jul 18 12:05:32 2013 -0700 15.3 @@ -48,6 +48,7 @@ 15.4 #include "oops/symbol.hpp" 15.5 #include "prims/jvmtiExport.hpp" 15.6 #include "prims/jvmtiRedefineClassesTrace.hpp" 15.7 +#include "prims/jvmtiRedefineClasses.hpp" 15.8 #include "prims/methodComparator.hpp" 15.9 #include "runtime/fieldDescriptor.hpp" 15.10 #include "runtime/handles.inline.hpp" 15.11 @@ -291,7 +292,7 @@ 15.12 set_initial_method_idnum(0); 15.13 _dependencies = NULL; 15.14 set_jvmti_cached_class_field_map(NULL); 15.15 - set_cached_class_file(NULL, 0); 15.16 + set_cached_class_file(NULL); 15.17 set_initial_method_idnum(0); 15.18 set_minor_version(0); 15.19 set_major_version(0); 15.20 @@ -2357,10 +2358,9 @@ 15.21 } 15.22 15.23 // deallocate the cached class file 15.24 - if (_cached_class_file_bytes != NULL) { 15.25 - os::free(_cached_class_file_bytes, mtClass); 15.26 - _cached_class_file_bytes = NULL; 15.27 - _cached_class_file_len = 0; 15.28 + if (_cached_class_file != NULL) { 15.29 + os::free(_cached_class_file, mtClass); 15.30 + _cached_class_file = NULL; 15.31 } 15.32 15.33 // Decrement symbol reference counts associated with the unloaded class. 15.34 @@ -3530,6 +3530,14 @@ 15.35 return m; 15.36 } 15.37 15.38 +jint InstanceKlass::get_cached_class_file_len() { 15.39 + return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file); 15.40 +} 15.41 + 15.42 +unsigned char * InstanceKlass::get_cached_class_file_bytes() { 15.43 + return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file); 15.44 +} 15.45 + 15.46 15.47 // Construct a PreviousVersionNode entry for the array hung off 15.48 // the InstanceKlass.
16.1 --- a/src/share/vm/oops/instanceKlass.hpp Thu Jul 18 09:35:02 2013 -0700 16.2 +++ b/src/share/vm/oops/instanceKlass.hpp Thu Jul 18 12:05:32 2013 -0700 16.3 @@ -133,6 +133,8 @@ 16.4 uint _count; 16.5 }; 16.6 16.7 +struct JvmtiCachedClassFileData; 16.8 + 16.9 class InstanceKlass: public Klass { 16.10 friend class VMStructs; 16.11 friend class ClassFileParser; 16.12 @@ -249,8 +251,8 @@ 16.13 // InstanceKlass. See PreviousVersionWalker below. 16.14 GrowableArray<PreviousVersionNode *>* _previous_versions; 16.15 // JVMTI fields can be moved to their own structure - see 6315920 16.16 - unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH 16.17 - jint _cached_class_file_len; // JVMTI: length of above 16.18 + // JVMTI: cached class file, before retransformable agent modified it in CFLH 16.19 + JvmtiCachedClassFileData* _cached_class_file; 16.20 16.21 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change 16.22 16.23 @@ -615,11 +617,12 @@ 16.24 static void purge_previous_versions(InstanceKlass* ik); 16.25 16.26 // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation 16.27 - void set_cached_class_file(unsigned char *class_file_bytes, 16.28 - jint class_file_len) { _cached_class_file_len = class_file_len; 16.29 - _cached_class_file_bytes = class_file_bytes; } 16.30 - jint get_cached_class_file_len() { return _cached_class_file_len; } 16.31 - unsigned char * get_cached_class_file_bytes() { return _cached_class_file_bytes; } 16.32 + void set_cached_class_file(JvmtiCachedClassFileData *data) { 16.33 + _cached_class_file = data; 16.34 + } 16.35 + JvmtiCachedClassFileData * get_cached_class_file() { return _cached_class_file; } 16.36 + jint get_cached_class_file_len(); 16.37 + unsigned char * get_cached_class_file_bytes(); 16.38 16.39 // JVMTI: Support for caching of field indices, types, and offsets 16.40 void set_jvmti_cached_class_field_map(JvmtiCachedClassFieldMap* descriptor) {
17.1 --- a/src/share/vm/prims/forte.cpp Thu Jul 18 09:35:02 2013 -0700 17.2 +++ b/src/share/vm/prims/forte.cpp Thu Jul 18 12:05:32 2013 -0700 17.3 @@ -31,6 +31,7 @@ 17.4 #include "oops/oop.inline.hpp" 17.5 #include "oops/oop.inline2.hpp" 17.6 #include "prims/forte.hpp" 17.7 +#include "runtime/javaCalls.hpp" 17.8 #include "runtime/thread.hpp" 17.9 #include "runtime/vframe.hpp" 17.10 #include "runtime/vframeArray.hpp" 17.11 @@ -308,10 +309,14 @@ 17.12 17.13 for (loop_count = 0; loop_count < loop_max; loop_count++) { 17.14 17.15 - if (candidate.is_first_frame()) { 17.16 + if (candidate.is_entry_frame()) { 17.17 + // jcw is NULL if the java call wrapper couldn't be found 17.18 + JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(thread); 17.19 // If initial frame is frame from StubGenerator and there is no 17.20 // previous anchor, there are no java frames associated with a method 17.21 - return false; 17.22 + if (jcw == NULL || jcw->is_first_frame()) { 17.23 + return false; 17.24 + } 17.25 } 17.26 17.27 if (candidate.is_interpreted_frame()) {
18.1 --- a/src/share/vm/prims/jniCheck.cpp Thu Jul 18 09:35:02 2013 -0700 18.2 +++ b/src/share/vm/prims/jniCheck.cpp Thu Jul 18 12:05:32 2013 -0700 18.3 @@ -126,6 +126,7 @@ 18.4 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call"; 18.5 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations"; 18.6 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation"; 18.7 +static const char * fatal_prim_type_array_expected = "Primitive type array expected but not received for JNI array operation"; 18.8 static const char * fatal_non_array = "Non-array passed to JNI array operations"; 18.9 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI"; 18.10 static const char * fatal_should_be_static = "Non-static field ID passed to JNI"; 18.11 @@ -278,30 +279,49 @@ 18.12 ReportJNIFatalError(thr, fatal_non_string); 18.13 } 18.14 18.15 -static inline void 18.16 -checkArray(JavaThread* thr, jarray jArray, int elementType) 18.17 +static inline arrayOop 18.18 +check_is_array(JavaThread* thr, jarray jArray) 18.19 { 18.20 ASSERT_OOPS_ALLOWED; 18.21 arrayOop aOop; 18.22 18.23 aOop = (arrayOop)jniCheck::validate_object(thr, jArray); 18.24 - if (aOop == NULL || !aOop->is_array()) 18.25 + if (aOop == NULL || !aOop->is_array()) { 18.26 ReportJNIFatalError(thr, fatal_non_array); 18.27 + } 18.28 + return aOop; 18.29 +} 18.30 18.31 - if (elementType != -1) { 18.32 - if (aOop->is_typeArray()) { 18.33 - BasicType array_type = TypeArrayKlass::cast(aOop->klass())->element_type(); 18.34 - if (array_type != elementType) 18.35 - ReportJNIFatalError(thr, fatal_element_type_mismatch); 18.36 - } else if (aOop->is_objArray()) { 18.37 - if ( T_OBJECT != elementType) 18.38 - ReportJNIFatalError(thr, fatal_object_array_expected); 18.39 - } else { 18.40 - ReportJNIFatalError(thr, fatal_unknown_array_object); 18.41 - } 18.42 +static inline arrayOop 18.43 +check_is_primitive_array(JavaThread* thr, jarray jArray) { 18.44 + arrayOop aOop = check_is_array(thr, jArray); 18.45 + 18.46 + if (!aOop->is_typeArray()) { 18.47 + ReportJNIFatalError(thr, fatal_prim_type_array_expected); 18.48 + } 18.49 + return aOop; 18.50 +} 18.51 + 18.52 +static inline void 18.53 +check_primitive_array_type(JavaThread* thr, jarray jArray, BasicType elementType) 18.54 +{ 18.55 + BasicType array_type; 18.56 + arrayOop aOop; 18.57 + 18.58 + aOop = check_is_primitive_array(thr, jArray); 18.59 + array_type = TypeArrayKlass::cast(aOop->klass())->element_type(); 18.60 + if (array_type != elementType) { 18.61 + ReportJNIFatalError(thr, fatal_element_type_mismatch); 18.62 } 18.63 } 18.64 18.65 +static inline void 18.66 +check_is_obj_array(JavaThread* thr, jarray jArray) { 18.67 + arrayOop aOop = check_is_array(thr, jArray); 18.68 + if (!aOop->is_objArray()) { 18.69 + ReportJNIFatalError(thr, fatal_object_array_expected); 18.70 + } 18.71 +} 18.72 18.73 oop jniCheck::validate_handle(JavaThread* thr, jobject obj) { 18.74 if (JNIHandles::is_frame_handle(thr, obj) || 18.75 @@ -1417,7 +1437,7 @@ 18.76 jarray array)) 18.77 functionEnter(thr); 18.78 IN_VM( 18.79 - checkArray(thr, array, -1); 18.80 + check_is_array(thr, array); 18.81 ) 18.82 jsize result = UNCHECKED()->GetArrayLength(env,array); 18.83 functionExit(env); 18.84 @@ -1441,7 +1461,7 @@ 18.85 jsize index)) 18.86 functionEnter(thr); 18.87 IN_VM( 18.88 - checkArray(thr, array, T_OBJECT); 18.89 + check_is_obj_array(thr, array); 18.90 ) 18.91 jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index); 18.92 functionExit(env); 18.93 @@ -1455,7 +1475,7 @@ 18.94 jobject val)) 18.95 functionEnter(thr); 18.96 IN_VM( 18.97 - checkArray(thr, array, T_OBJECT); 18.98 + check_is_obj_array(thr, array); 18.99 ) 18.100 UNCHECKED()->SetObjectArrayElement(env,array,index,val); 18.101 functionExit(env); 18.102 @@ -1487,7 +1507,7 @@ 18.103 jboolean *isCopy)) \ 18.104 functionEnter(thr); \ 18.105 IN_VM( \ 18.106 - checkArray(thr, array, ElementTag); \ 18.107 + check_primitive_array_type(thr, array, ElementTag); \ 18.108 ) \ 18.109 ElementType *result = UNCHECKED()->Get##Result##ArrayElements(env, \ 18.110 array, \ 18.111 @@ -1513,7 +1533,7 @@ 18.112 jint mode)) \ 18.113 functionEnterExceptionAllowed(thr); \ 18.114 IN_VM( \ 18.115 - checkArray(thr, array, ElementTag); \ 18.116 + check_primitive_array_type(thr, array, ElementTag); \ 18.117 ASSERT_OOPS_ALLOWED; \ 18.118 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ 18.119 /* cannot check validity of copy, unless every request is logged by 18.120 @@ -1543,7 +1563,7 @@ 18.121 ElementType *buf)) \ 18.122 functionEnter(thr); \ 18.123 IN_VM( \ 18.124 - checkArray(thr, array, ElementTag); \ 18.125 + check_primitive_array_type(thr, array, ElementTag); \ 18.126 ) \ 18.127 UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \ 18.128 functionExit(env); \ 18.129 @@ -1567,7 +1587,7 @@ 18.130 const ElementType *buf)) \ 18.131 functionEnter(thr); \ 18.132 IN_VM( \ 18.133 - checkArray(thr, array, ElementTag); \ 18.134 + check_primitive_array_type(thr, array, ElementTag); \ 18.135 ) \ 18.136 UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \ 18.137 functionExit(env); \ 18.138 @@ -1669,7 +1689,7 @@ 18.139 jboolean *isCopy)) 18.140 functionEnterCritical(thr); 18.141 IN_VM( 18.142 - checkArray(thr, array, -1); 18.143 + check_is_primitive_array(thr, array); 18.144 ) 18.145 void *result = UNCHECKED()->GetPrimitiveArrayCritical(env, array, isCopy); 18.146 functionExit(env); 18.147 @@ -1683,7 +1703,7 @@ 18.148 jint mode)) 18.149 functionEnterCriticalExceptionAllowed(thr); 18.150 IN_VM( 18.151 - checkArray(thr, array, -1); 18.152 + check_is_primitive_array(thr, array); 18.153 ) 18.154 /* The Hotspot JNI code does not use the parameters, so just check the 18.155 * array parameter as a minor sanity check
19.1 --- a/src/share/vm/prims/jvmtiExport.cpp Thu Jul 18 09:35:02 2013 -0700 19.2 +++ b/src/share/vm/prims/jvmtiExport.cpp Thu Jul 18 12:05:32 2013 -0700 19.3 @@ -41,6 +41,7 @@ 19.4 #include "prims/jvmtiRawMonitor.hpp" 19.5 #include "prims/jvmtiTagMap.hpp" 19.6 #include "prims/jvmtiThreadState.inline.hpp" 19.7 +#include "prims/jvmtiRedefineClasses.hpp" 19.8 #include "runtime/arguments.hpp" 19.9 #include "runtime/handles.hpp" 19.10 #include "runtime/interfaceSupport.hpp" 19.11 @@ -516,8 +517,7 @@ 19.12 jint _curr_len; 19.13 unsigned char * _curr_data; 19.14 JvmtiEnv * _curr_env; 19.15 - jint * _cached_length_ptr; 19.16 - unsigned char ** _cached_data_ptr; 19.17 + JvmtiCachedClassFileData ** _cached_class_file_ptr; 19.18 JvmtiThreadState * _state; 19.19 KlassHandle * _h_class_being_redefined; 19.20 JvmtiClassLoadKind _load_kind; 19.21 @@ -526,8 +526,7 @@ 19.22 inline JvmtiClassFileLoadHookPoster(Symbol* h_name, Handle class_loader, 19.23 Handle h_protection_domain, 19.24 unsigned char **data_ptr, unsigned char **end_ptr, 19.25 - unsigned char **cached_data_ptr, 19.26 - jint *cached_length_ptr) { 19.27 + JvmtiCachedClassFileData **cache_ptr) { 19.28 _h_name = h_name; 19.29 _class_loader = class_loader; 19.30 _h_protection_domain = h_protection_domain; 19.31 @@ -537,8 +536,7 @@ 19.32 _curr_len = *end_ptr - *data_ptr; 19.33 _curr_data = *data_ptr; 19.34 _curr_env = NULL; 19.35 - _cached_length_ptr = cached_length_ptr; 19.36 - _cached_data_ptr = cached_data_ptr; 19.37 + _cached_class_file_ptr = cache_ptr; 19.38 19.39 _state = _thread->jvmti_thread_state(); 19.40 if (_state != NULL) { 19.41 @@ -615,15 +613,20 @@ 19.42 } 19.43 if (new_data != NULL) { 19.44 // this agent has modified class data. 19.45 - if (caching_needed && *_cached_data_ptr == NULL) { 19.46 + if (caching_needed && *_cached_class_file_ptr == NULL) { 19.47 // data has been changed by the new retransformable agent 19.48 // and it hasn't already been cached, cache it 19.49 - *_cached_data_ptr = (unsigned char *)os::malloc(_curr_len, mtInternal); 19.50 - if (*_cached_data_ptr == NULL) { 19.51 - vm_exit_out_of_memory(_curr_len, OOM_MALLOC_ERROR, "unable to allocate cached copy of original class bytes"); 19.52 + JvmtiCachedClassFileData *p; 19.53 + p = (JvmtiCachedClassFileData *)os::malloc( 19.54 + offset_of(JvmtiCachedClassFileData, data) + _curr_len, mtInternal); 19.55 + if (p == NULL) { 19.56 + vm_exit_out_of_memory(offset_of(JvmtiCachedClassFileData, data) + _curr_len, 19.57 + OOM_MALLOC_ERROR, 19.58 + "unable to allocate cached copy of original class bytes"); 19.59 } 19.60 - memcpy(*_cached_data_ptr, _curr_data, _curr_len); 19.61 - *_cached_length_ptr = _curr_len; 19.62 + p->length = _curr_len; 19.63 + memcpy(p->data, _curr_data, _curr_len); 19.64 + *_cached_class_file_ptr = p; 19.65 } 19.66 19.67 if (_curr_data != *_data_ptr) { 19.68 @@ -662,13 +665,11 @@ 19.69 Handle h_protection_domain, 19.70 unsigned char **data_ptr, 19.71 unsigned char **end_ptr, 19.72 - unsigned char **cached_data_ptr, 19.73 - jint *cached_length_ptr) { 19.74 + JvmtiCachedClassFileData **cache_ptr) { 19.75 JvmtiClassFileLoadHookPoster poster(h_name, class_loader, 19.76 h_protection_domain, 19.77 data_ptr, end_ptr, 19.78 - cached_data_ptr, 19.79 - cached_length_ptr); 19.80 + cache_ptr); 19.81 poster.post(); 19.82 } 19.83
20.1 --- a/src/share/vm/prims/jvmtiExport.hpp Thu Jul 18 09:35:02 2013 -0700 20.2 +++ b/src/share/vm/prims/jvmtiExport.hpp Thu Jul 18 12:05:32 2013 -0700 20.3 @@ -323,8 +323,7 @@ 20.4 static void post_class_file_load_hook(Symbol* h_name, Handle class_loader, 20.5 Handle h_protection_domain, 20.6 unsigned char **data_ptr, unsigned char **end_ptr, 20.7 - unsigned char **cached_data_ptr, 20.8 - jint *cached_length_ptr) NOT_JVMTI_RETURN; 20.9 + JvmtiCachedClassFileData **cache_ptr) NOT_JVMTI_RETURN; 20.10 static void post_native_method_bind(Method* method, address* function_ptr) NOT_JVMTI_RETURN; 20.11 static void post_compiled_method_load(nmethod *nm) NOT_JVMTI_RETURN; 20.12 static void post_dynamic_code_generated(const char *name, const void *code_begin, const void *code_end) NOT_JVMTI_RETURN;
21.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Thu Jul 18 09:35:02 2013 -0700 21.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Thu Jul 18 12:05:32 2013 -0700 21.3 @@ -3342,9 +3342,7 @@ 21.4 // should get cleared in the_class too. 21.5 if (the_class->get_cached_class_file_bytes() == 0) { 21.6 // the_class doesn't have a cache yet so copy it 21.7 - the_class->set_cached_class_file( 21.8 - scratch_class->get_cached_class_file_bytes(), 21.9 - scratch_class->get_cached_class_file_len()); 21.10 + the_class->set_cached_class_file(scratch_class->get_cached_class_file()); 21.11 } 21.12 #ifndef PRODUCT 21.13 else { 21.14 @@ -3357,7 +3355,7 @@ 21.15 21.16 // NULL out in scratch class to not delete twice. The class to be redefined 21.17 // always owns these bytes. 21.18 - scratch_class->set_cached_class_file(NULL, 0); 21.19 + scratch_class->set_cached_class_file(NULL); 21.20 21.21 // Replace inner_classes 21.22 Array<u2>* old_inner_classes = the_class->inner_classes();
22.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Thu Jul 18 09:35:02 2013 -0700 22.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Thu Jul 18 12:05:32 2013 -0700 22.3 @@ -331,6 +331,11 @@ 22.4 // coordinate a cleanup of these constants with Runtime. 22.5 // 22.6 22.7 +struct JvmtiCachedClassFileData { 22.8 + jint length; 22.9 + unsigned char data[1]; 22.10 +}; 22.11 + 22.12 class VM_RedefineClasses: public VM_Operation { 22.13 private: 22.14 // These static fields are needed by ClassLoaderDataGraph::classes_do() 22.15 @@ -509,5 +514,12 @@ 22.16 // Modifiable test must be shared between IsModifiableClass query 22.17 // and redefine implementation 22.18 static bool is_modifiable_class(oop klass_mirror); 22.19 + 22.20 + static jint get_cached_class_file_len(JvmtiCachedClassFileData *cache) { 22.21 + return cache == NULL ? 0 : cache->length; 22.22 + } 22.23 + static unsigned char * get_cached_class_file_bytes(JvmtiCachedClassFileData *cache) { 22.24 + return cache == NULL ? NULL : cache->data; 22.25 + } 22.26 }; 22.27 #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
23.1 --- a/src/share/vm/runtime/frame.cpp Thu Jul 18 09:35:02 2013 -0700 23.2 +++ b/src/share/vm/runtime/frame.cpp Thu Jul 18 12:05:32 2013 -0700 23.3 @@ -221,9 +221,20 @@ 23.4 23.5 23.6 bool frame::entry_frame_is_first() const { 23.7 - return entry_frame_call_wrapper()->anchor()->last_Java_sp() == NULL; 23.8 + return entry_frame_call_wrapper()->is_first_frame(); 23.9 } 23.10 23.11 +JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const { 23.12 + JavaCallWrapper** jcw = entry_frame_call_wrapper_addr(); 23.13 + address addr = (address) jcw; 23.14 + 23.15 + // addr must be within the usable part of the stack 23.16 + if (thread->is_in_usable_stack(addr)) { 23.17 + return *jcw; 23.18 + } 23.19 + 23.20 + return NULL; 23.21 +} 23.22 23.23 bool frame::should_be_deoptimized() const { 23.24 if (_deopt_state == is_deoptimized ||
24.1 --- a/src/share/vm/runtime/frame.hpp Thu Jul 18 09:35:02 2013 -0700 24.2 +++ b/src/share/vm/runtime/frame.hpp Thu Jul 18 12:05:32 2013 -0700 24.3 @@ -353,7 +353,9 @@ 24.4 24.5 public: 24.6 // Entry frames 24.7 - JavaCallWrapper* entry_frame_call_wrapper() const; 24.8 + JavaCallWrapper* entry_frame_call_wrapper() const { return *entry_frame_call_wrapper_addr(); } 24.9 + JavaCallWrapper* entry_frame_call_wrapper_if_safe(JavaThread* thread) const; 24.10 + JavaCallWrapper** entry_frame_call_wrapper_addr() const; 24.11 intptr_t* entry_frame_argument_at(int offset) const; 24.12 24.13 // tells whether there is another chunk of Delta stack above
25.1 --- a/src/share/vm/runtime/javaCalls.hpp Thu Jul 18 09:35:02 2013 -0700 25.2 +++ b/src/share/vm/runtime/javaCalls.hpp Thu Jul 18 12:05:32 2013 -0700 25.3 @@ -80,6 +80,8 @@ 25.4 oop receiver() { return _receiver; } 25.5 void oops_do(OopClosure* f); 25.6 25.7 + bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; } 25.8 + 25.9 }; 25.10 25.11
26.1 --- a/src/share/vm/runtime/thread.cpp Thu Jul 18 09:35:02 2013 -0700 26.2 +++ b/src/share/vm/runtime/thread.cpp Thu Jul 18 12:05:32 2013 -0700 26.3 @@ -218,6 +218,7 @@ 26.4 // allocated data structures 26.5 set_osthread(NULL); 26.6 set_resource_area(new (mtThread)ResourceArea()); 26.7 + DEBUG_ONLY(_current_resource_mark = NULL;) 26.8 set_handle_area(new (mtThread) HandleArea(NULL)); 26.9 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true)); 26.10 set_active_handles(NULL); 26.11 @@ -953,6 +954,14 @@ 26.12 } 26.13 26.14 26.15 +bool Thread::is_in_usable_stack(address adr) const { 26.16 + size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0; 26.17 + size_t usable_stack_size = _stack_size - stack_guard_size; 26.18 + 26.19 + return ((adr < stack_base()) && (adr >= stack_base() - usable_stack_size)); 26.20 +} 26.21 + 26.22 + 26.23 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter 26.24 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being 26.25 // used for compilation in the future. If that change is made, the need for these methods 26.26 @@ -3636,6 +3645,7 @@ 26.27 26.28 // Start Attach Listener if +StartAttachListener or it can't be started lazily 26.29 if (!DisableAttachMechanism) { 26.30 + AttachListener::vm_start(); 26.31 if (StartAttachListener || AttachListener::init_at_startup()) { 26.32 AttachListener::init(); 26.33 }
27.1 --- a/src/share/vm/runtime/thread.hpp Thu Jul 18 09:35:02 2013 -0700 27.2 +++ b/src/share/vm/runtime/thread.hpp Thu Jul 18 12:05:32 2013 -0700 27.3 @@ -86,6 +86,8 @@ 27.4 class ThreadClosure; 27.5 class IdealGraphPrinter; 27.6 27.7 +DEBUG_ONLY(class ResourceMark;) 27.8 + 27.9 class WorkerThread; 27.10 27.11 // Class hierarchy 27.12 @@ -519,6 +521,9 @@ 27.13 // Check if address is in the stack of the thread (not just for locks). 27.14 // Warning: the method can only be used on the running thread 27.15 bool is_in_stack(address adr) const; 27.16 + // Check if address is in the usable part of the stack (excludes protected 27.17 + // guard pages) 27.18 + bool is_in_usable_stack(address adr) const; 27.19 27.20 // Sets this thread as starting thread. Returns failure if thread 27.21 // creation fails due to lack of memory, too many threads etc. 27.22 @@ -531,6 +536,8 @@ 27.23 // Thread local resource area for temporary allocation within the VM 27.24 ResourceArea* _resource_area; 27.25 27.26 + DEBUG_ONLY(ResourceMark* _current_resource_mark;) 27.27 + 27.28 // Thread local handle area for allocation of handles within the VM 27.29 HandleArea* _handle_area; 27.30 GrowableArray<Metadata*>* _metadata_handles; 27.31 @@ -585,6 +592,8 @@ 27.32 27.33 // Deadlock detection 27.34 bool allow_allocation() { return _allow_allocation_count == 0; } 27.35 + ResourceMark* current_resource_mark() { return _current_resource_mark; } 27.36 + void set_current_resource_mark(ResourceMark* rm) { _current_resource_mark = rm; } 27.37 #endif 27.38 27.39 void check_for_valid_safepoint_state(bool potential_vm_operation) PRODUCT_RETURN;
28.1 --- a/src/share/vm/services/attachListener.hpp Thu Jul 18 09:35:02 2013 -0700 28.2 +++ b/src/share/vm/services/attachListener.hpp Thu Jul 18 12:05:32 2013 -0700 28.3 @@ -50,6 +50,7 @@ 28.4 28.5 class AttachListener: AllStatic { 28.6 public: 28.7 + static void vm_start() NOT_SERVICES_RETURN; 28.8 static void init() NOT_SERVICES_RETURN; 28.9 static void abort() NOT_SERVICES_RETURN; 28.10
29.1 --- a/src/share/vm/services/memTracker.cpp Thu Jul 18 09:35:02 2013 -0700 29.2 +++ b/src/share/vm/services/memTracker.cpp Thu Jul 18 12:05:32 2013 -0700 29.3 @@ -385,6 +385,7 @@ 29.4 #define SAFE_SEQUENCE_THRESHOLD 30 29.5 #define HIGH_GENERATION_THRESHOLD 60 29.6 #define MAX_RECORDER_THREAD_RATIO 30 29.7 +#define MAX_RECORDER_PER_THREAD 100 29.8 29.9 void MemTracker::sync() { 29.10 assert(_tracking_level > NMT_off, "NMT is not enabled"); 29.11 @@ -437,6 +438,11 @@ 29.12 // means that worker thread is lagging behind in processing them. 29.13 if (!AutoShutdownNMT) { 29.14 _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count); 29.15 + } else { 29.16 + // If auto shutdown is on, enforce MAX_RECORDER_PER_THREAD threshold to prevent OOM 29.17 + if (MemRecorder::_instance_count >= _thread_count * MAX_RECORDER_PER_THREAD) { 29.18 + shutdown(NMT_out_of_memory); 29.19 + } 29.20 } 29.21 29.22 // check _worker_thread with lock to avoid racing condition
30.1 --- a/src/share/vm/utilities/ostream.cpp Thu Jul 18 09:35:02 2013 -0700 30.2 +++ b/src/share/vm/utilities/ostream.cpp Thu Jul 18 12:05:32 2013 -0700 30.3 @@ -296,6 +296,7 @@ 30.4 buffer = NEW_RESOURCE_ARRAY(char, buffer_length); 30.5 buffer_pos = 0; 30.6 buffer_fixed = false; 30.7 + DEBUG_ONLY(rm = Thread::current()->current_resource_mark();) 30.8 } 30.9 30.10 // useful for output to fixed chunks of memory, such as performance counters 30.11 @@ -321,6 +322,8 @@ 30.12 end = buffer_length * 2; 30.13 } 30.14 char* oldbuf = buffer; 30.15 + assert(rm == NULL || Thread::current()->current_resource_mark() == rm, 30.16 + "stringStream is re-allocated with a different ResourceMark"); 30.17 buffer = NEW_RESOURCE_ARRAY(char, end); 30.18 strncpy(buffer, oldbuf, buffer_pos); 30.19 buffer_length = end;
31.1 --- a/src/share/vm/utilities/ostream.hpp Thu Jul 18 09:35:02 2013 -0700 31.2 +++ b/src/share/vm/utilities/ostream.hpp Thu Jul 18 12:05:32 2013 -0700 31.3 @@ -28,6 +28,8 @@ 31.4 #include "memory/allocation.hpp" 31.5 #include "runtime/timer.hpp" 31.6 31.7 +DEBUG_ONLY(class ResourceMark;) 31.8 + 31.9 // Output streams for printing 31.10 // 31.11 // Printing guidelines: 31.12 @@ -177,6 +179,7 @@ 31.13 size_t buffer_pos; 31.14 size_t buffer_length; 31.15 bool buffer_fixed; 31.16 + DEBUG_ONLY(ResourceMark* rm;) 31.17 public: 31.18 stringStream(size_t initial_bufsize = 256); 31.19 stringStream(char* fixed_buffer, size_t fixed_buffer_size);
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/runtime/jsig/Test8017498.sh Thu Jul 18 12:05:32 2013 -0700 32.3 @@ -0,0 +1,95 @@ 32.4 +#!/bin/sh 32.5 + 32.6 +# 32.7 +# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 32.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.9 +# 32.10 +# This code is free software; you can redistribute it and/or modify it 32.11 +# under the terms of the GNU General Public License version 2 only, as 32.12 +# published by the Free Software Foundation. 32.13 +# 32.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 32.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.17 +# version 2 for more details (a copy is included in the LICENSE file that 32.18 +# accompanied this code). 32.19 +# 32.20 +# You should have received a copy of the GNU General Public License version 32.21 +# 2 along with this work; if not, write to the Free Software Foundation, 32.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.23 +# 32.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.25 +# or visit www.oracle.com if you need additional information or have any 32.26 +# questions. 32.27 +# 32.28 + 32.29 +## 32.30 +## @test Test8017498.sh 32.31 +## @bug 8017498 32.32 +## @summary sigaction(sig) results in process hang/timed-out if sig is much greater than SIGRTMAX 32.33 +## @run shell Test8017498.sh 32.34 +## 32.35 + 32.36 +if [ "${TESTSRC}" = "" ] 32.37 +then 32.38 + TESTSRC=${PWD} 32.39 + echo "TESTSRC not set. Using "${TESTSRC}" as default" 32.40 +fi 32.41 +echo "TESTSRC=${TESTSRC}" 32.42 +## Adding common setup Variables for running shell tests. 32.43 +. ${TESTSRC}/../../test_env.sh 32.44 + 32.45 +# set platform-dependent variables 32.46 +OS=`uname -s` 32.47 +case "$OS" in 32.48 + Linux) 32.49 + echo "Testing on Linux" 32.50 + if [ "$VM_BITS" = "64" ] 32.51 + then 32.52 + LD_PRELOAD=${TESTJAVA}${FS}jre${FS}lib${FS}amd64${FS}libjsig.so 32.53 + else 32.54 + LD_PRELOAD=${TESTJAVA}${FS}jre${FS}lib${FS}i386${FS}libjsig.so 32.55 + fi 32.56 + echo LD_PRELOAD = ${LD_PRELOAD} 32.57 + export LD_PRELOAD=${LD_PRELOAD} 32.58 + ;; 32.59 + *) 32.60 + NULL=NUL 32.61 + PS=";" 32.62 + FS="\\" 32.63 + echo "Test passed; only valid for Linux" 32.64 + exit 0; 32.65 + ;; 32.66 +esac 32.67 + 32.68 +THIS_DIR=. 32.69 + 32.70 +cp ${TESTSRC}${FS}*.java ${THIS_DIR} 32.71 +${TESTJAVA}${FS}bin${FS}javac *.java 32.72 + 32.73 +gcc -fPIC -shared -o ${TESTSRC}${FS}libTestJNI.so -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux ${TESTSRC}${FS}TestJNI.c 32.74 + 32.75 +# run the java test in the background 32.76 +echo ${TESTJAVA}${FS}bin${FS}java -Djava.library.path=${TESTSRC}${FS} -server TestJNI 100 > test.out 2>&1 & 32.77 +${TESTJAVA}${FS}bin${FS}java -Djava.library.path=${TESTSRC}${FS} -server TestJNI 100 > test.out 2>&1 & 32.78 + 32.79 +# obtain the process id 32.80 +C_PID=$! 32.81 + 32.82 +# sleep for 1s 32.83 +sleep 1 32.84 + 32.85 +# reset LD_PRELOAD 32.86 +unset LD_PRELOAD 32.87 + 32.88 +# check the output file (test.out) 32.89 +grep "old handler" test.out > ${NULL} 32.90 +if [ $? = 0 ] 32.91 +then 32.92 + echo "Test Passed" 32.93 + exit 0 32.94 +else 32.95 + kill -9 ${C_PID} 32.96 + echo "Test Failed" 32.97 + exit 1 32.98 +fi
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/runtime/jsig/TestJNI.c Thu Jul 18 12:05:32 2013 -0700 33.3 @@ -0,0 +1,61 @@ 33.4 +/* 33.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. 33.11 + * 33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.15 + * version 2 for more details (a copy is included in the LICENSE file that 33.16 + * accompanied this code). 33.17 + * 33.18 + * You should have received a copy of the GNU General Public License version 33.19 + * 2 along with this work; if not, write to the Free Software Foundation, 33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.21 + * 33.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 33.23 + * or visit www.oracle.com if you need additional information or have any 33.24 + * questions. 33.25 + */ 33.26 + 33.27 +#include <stdio.h> 33.28 +#include <jni.h> 33.29 +#define __USE_GNU 33.30 +#include <signal.h> 33.31 +#include <sys/ucontext.h> 33.32 + 33.33 +#ifdef __cplusplus 33.34 +extern "C" { 33.35 +#endif 33.36 + 33.37 +void sig_handler(int sig, siginfo_t *info, ucontext_t *context) { 33.38 + int thrNum; 33.39 + 33.40 + printf( " HANDLER (1) " ); 33.41 + // Move forward RIP to skip failing instruction 33.42 + context->uc_mcontext.gregs[REG_RIP] += 6; 33.43 +} 33.44 + 33.45 +JNIEXPORT void JNICALL Java_TestJNI_doSomething(JNIEnv *env, jclass klass, jint val) { 33.46 + struct sigaction act; 33.47 + struct sigaction oact; 33.48 + pthread_attr_t attr; 33.49 + stack_t stack; 33.50 + 33.51 + act.sa_flags = SA_ONSTACK|SA_RESTART|SA_SIGINFO; 33.52 + sigfillset(&act.sa_mask); 33.53 + act.sa_handler = SIG_DFL; 33.54 + act.sa_sigaction = (void (*)())sig_handler; 33.55 + sigaction(0x20+val, &act, &oact); 33.56 + 33.57 + printf( " doSomething(%d) " , val); 33.58 + printf( " old handler = %p " , oact.sa_handler); 33.59 +} 33.60 + 33.61 +#ifdef __cplusplus 33.62 +} 33.63 +#endif 33.64 +
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/runtime/jsig/TestJNI.java Thu Jul 18 12:05:32 2013 -0700 34.3 @@ -0,0 +1,42 @@ 34.4 +/* 34.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. 34.11 + * 34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.15 + * version 2 for more details (a copy is included in the LICENSE file that 34.16 + * accompanied this code). 34.17 + * 34.18 + * You should have received a copy of the GNU General Public License version 34.19 + * 2 along with this work; if not, write to the Free Software Foundation, 34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.21 + * 34.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.23 + * or visit www.oracle.com if you need additional information or have any 34.24 + * questions. 34.25 + */ 34.26 + 34.27 +public class TestJNI { 34.28 + static { 34.29 + System.loadLibrary("TestJNI"); 34.30 + } 34.31 + public static native void doSomething(int val); 34.32 + public static void main(String[] args) { 34.33 + int intArg = 43; 34.34 + if (args.length > 0) { 34.35 + try { 34.36 + intArg = Integer.parseInt(args[0]); 34.37 + } catch (NumberFormatException e) { 34.38 + System.err.println("arg " + args[0] + " must be an integer"); 34.39 + System.exit(1); 34.40 + } 34.41 + } 34.42 + TestJNI.doSomething(intArg); 34.43 + } 34.44 +} 34.45 +
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/serviceability/attach/AttachWithStalePidFile.java Thu Jul 18 12:05:32 2013 -0700 35.3 @@ -0,0 +1,139 @@ 35.4 +/* 35.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.23 + * or visit www.oracle.com if you need additional information or have any 35.24 + * questions. 35.25 + */ 35.26 + 35.27 +/* 35.28 + * @test 35.29 + * @bug 7162400 35.30 + * @key regression 35.31 + * @summary Regression test for attach issue where stale pid files in /tmp lead to connection issues 35.32 + * @library /testlibrary 35.33 + * @compile AttachWithStalePidFileTarget.java 35.34 + * @run main AttachWithStalePidFile 35.35 + */ 35.36 + 35.37 +import com.oracle.java.testlibrary.*; 35.38 +import com.sun.tools.attach.VirtualMachine; 35.39 +import sun.tools.attach.HotSpotVirtualMachine; 35.40 +import java.lang.reflect.Field; 35.41 +import java.nio.file.*; 35.42 +import java.nio.file.attribute.*; 35.43 +import java.io.*; 35.44 + 35.45 +public class AttachWithStalePidFile { 35.46 + public static void main(String... args) throws Exception { 35.47 + 35.48 + // this test is only valid on non-Windows platforms 35.49 + if(Platform.isWindows()) { 35.50 + System.out.println("This test is only valid on non-Windows platforms."); 35.51 + return; 35.52 + } 35.53 + 35.54 + // Since there might be stale pid-files owned by different 35.55 + // users on the system we may need to retry the test in case we 35.56 + // are unable to remove the existing file. 35.57 + int retries = 5; 35.58 + while(!runTest() && --retries > 0); 35.59 + 35.60 + if(retries == 0) { 35.61 + throw new RuntimeException("Test failed after 5 retries. " + 35.62 + "Remove any /tmp/.java_pid* files and retry."); 35.63 + } 35.64 + } 35.65 + 35.66 + public static boolean runTest() throws Exception { 35.67 + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 35.68 + "-XX:+UnlockDiagnosticVMOptions", "-XX:+PauseAtStartup", "AttachWithStalePidFileTarget"); 35.69 + Process target = pb.start(); 35.70 + Path pidFile = null; 35.71 + 35.72 + try { 35.73 + int pid = getUnixProcessId(target); 35.74 + 35.75 + // create the stale .java_pid file. use hard-coded /tmp path as in th VM 35.76 + pidFile = createJavaPidFile(pid); 35.77 + if(pidFile == null) { 35.78 + return false; 35.79 + } 35.80 + 35.81 + // wait for vm.paused file to be created and delete it once we find it. 35.82 + waitForAndResumeVM(pid); 35.83 + 35.84 + // unfortunately there's no reliable way to know the VM is ready to receive the 35.85 + // attach request so we have to do an arbitrary sleep. 35.86 + Thread.sleep(5000); 35.87 + 35.88 + HotSpotVirtualMachine vm = (HotSpotVirtualMachine)VirtualMachine.attach(((Integer)pid).toString()); 35.89 + BufferedReader remoteDataReader = new BufferedReader(new InputStreamReader(vm.remoteDataDump())); 35.90 + String line = null; 35.91 + while((line = remoteDataReader.readLine()) != null); 35.92 + 35.93 + vm.detach(); 35.94 + return true; 35.95 + } 35.96 + finally { 35.97 + target.destroy(); 35.98 + target.waitFor(); 35.99 + 35.100 + if(pidFile != null && Files.exists(pidFile)) { 35.101 + Files.delete(pidFile); 35.102 + } 35.103 + } 35.104 + } 35.105 + 35.106 + private static Path createJavaPidFile(int pid) throws Exception { 35.107 + Path pidFile = Paths.get("/tmp/.java_pid" + pid); 35.108 + if(Files.exists(pidFile)) { 35.109 + try { 35.110 + Files.delete(pidFile); 35.111 + } 35.112 + catch(FileSystemException e) { 35.113 + if(e.getReason().equals("Operation not permitted")) { 35.114 + System.out.println("Unable to remove exisiting stale PID file" + pidFile); 35.115 + return null; 35.116 + } 35.117 + throw e; 35.118 + } 35.119 + } 35.120 + return Files.createFile(pidFile, 35.121 + PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------"))); 35.122 + } 35.123 + 35.124 + private static void waitForAndResumeVM(int pid) throws Exception { 35.125 + Path pauseFile = Paths.get("vm.paused." + pid); 35.126 + int retries = 60; 35.127 + while(!Files.exists(pauseFile) && --retries > 0) { 35.128 + Thread.sleep(1000); 35.129 + } 35.130 + if(retries == 0) { 35.131 + throw new RuntimeException("Timeout waiting for VM to start. " + 35.132 + "vm.paused file not created within 60 seconds."); 35.133 + } 35.134 + Files.delete(pauseFile); 35.135 + } 35.136 + 35.137 + private static int getUnixProcessId(Process unixProcess) throws Exception { 35.138 + Field pidField = unixProcess.getClass().getDeclaredField("pid"); 35.139 + pidField.setAccessible(true); 35.140 + return (Integer)pidField.get(unixProcess); 35.141 + } 35.142 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/serviceability/attach/AttachWithStalePidFileTarget.java Thu Jul 18 12:05:32 2013 -0700 36.3 @@ -0,0 +1,27 @@ 36.4 +/* 36.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. 36.11 + * 36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.15 + * version 2 for more details (a copy is included in the LICENSE file that 36.16 + * accompanied this code). 36.17 + * 36.18 + * You should have received a copy of the GNU General Public License version 36.19 + * 2 along with this work; if not, write to the Free Software Foundation, 36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.21 + * 36.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 36.23 + * or visit www.oracle.com if you need additional information or have any 36.24 + * questions. 36.25 + */ 36.26 +public class AttachWithStalePidFileTarget { 36.27 + public static void main(String... args) throws Exception { 36.28 + Thread.sleep(2*60*1000); 36.29 + } 36.30 +}