Merge

Sat, 23 Mar 2013 22:35:02 -0700

author
dcubed
date
Sat, 23 Mar 2013 22:35:02 -0700
changeset 4813
6574f999e0cf
parent 4801
59a41e1357ab
parent 4812
14509df4cd63
child 4815
9c8e53c7bed0

Merge

src/share/vm/memory/metaspace.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Sat Mar 23 10:06:34 2013 -0700
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Sat Mar 23 22:35:02 2013 -0700
     1.3 @@ -1811,13 +1811,15 @@
     1.4  class VM_LinuxDllLoad: public VM_Operation {
     1.5   private:
     1.6    const char *_filename;
     1.7 +  char *_ebuf;
     1.8 +  int _ebuflen;
     1.9    void *_lib;
    1.10   public:
    1.11 -  VM_LinuxDllLoad(const char *fn) :
    1.12 -    _filename(fn), _lib(NULL) {}
    1.13 +  VM_LinuxDllLoad(const char *fn, char *ebuf, int ebuflen) :
    1.14 +    _filename(fn), _ebuf(ebuf), _ebuflen(ebuflen), _lib(NULL) {}
    1.15    VMOp_Type type() const { return VMOp_LinuxDllLoad; }
    1.16    void doit() {
    1.17 -    _lib = os::Linux::dll_load_inner(_filename);
    1.18 +    _lib = os::Linux::dll_load_in_vmthread(_filename, _ebuf, _ebuflen);
    1.19      os::Linux::_stack_is_executable = true;
    1.20    }
    1.21    void* loaded_library() { return _lib; }
    1.22 @@ -1865,13 +1867,13 @@
    1.23              // This is for the case where the DLL has an static
    1.24              // constructor function that executes JNI code. We cannot
    1.25              // load such DLLs in the VMThread.
    1.26 -            result = ::dlopen(filename, RTLD_LAZY);
    1.27 +            result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
    1.28            }
    1.29  
    1.30            ThreadInVMfromNative tiv(jt);
    1.31            debug_only(VMNativeEntryWrapper vew;)
    1.32  
    1.33 -          VM_LinuxDllLoad op(filename);
    1.34 +          VM_LinuxDllLoad op(filename, ebuf, ebuflen);
    1.35            VMThread::execute(&op);
    1.36            if (LoadExecStackDllInVMThread) {
    1.37              result = op.loaded_library();
    1.38 @@ -1883,7 +1885,7 @@
    1.39    }
    1.40  
    1.41    if (!load_attempted) {
    1.42 -    result = ::dlopen(filename, RTLD_LAZY);
    1.43 +    result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
    1.44    }
    1.45  
    1.46    if (result != NULL) {
    1.47 @@ -1892,11 +1894,6 @@
    1.48    }
    1.49  
    1.50    Elf32_Ehdr elf_head;
    1.51 -
    1.52 -  // Read system error message into ebuf
    1.53 -  // It may or may not be overwritten below
    1.54 -  ::strncpy(ebuf, ::dlerror(), ebuflen-1);
    1.55 -  ebuf[ebuflen-1]='\0';
    1.56    int diag_msg_max_length=ebuflen-strlen(ebuf);
    1.57    char* diag_msg_buf=ebuf+strlen(ebuf);
    1.58  
    1.59 @@ -2039,10 +2036,19 @@
    1.60    return NULL;
    1.61  }
    1.62  
    1.63 -void * os::Linux::dll_load_inner(const char *filename) {
    1.64 +void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
    1.65 +  void * result = ::dlopen(filename, RTLD_LAZY);
    1.66 +  if (result == NULL) {
    1.67 +    ::strncpy(ebuf, ::dlerror(), ebuflen - 1);
    1.68 +    ebuf[ebuflen-1] = '\0';
    1.69 +  }
    1.70 +  return result;
    1.71 +}
    1.72 +
    1.73 +void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) {
    1.74    void * result = NULL;
    1.75    if (LoadExecStackDllInVMThread) {
    1.76 -    result = ::dlopen(filename, RTLD_LAZY);
    1.77 +    result = dlopen_helper(filename, ebuf, ebuflen);
    1.78    }
    1.79  
    1.80    // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
     2.1 --- a/src/os/linux/vm/os_linux.hpp	Sat Mar 23 10:06:34 2013 -0700
     2.2 +++ b/src/os/linux/vm/os_linux.hpp	Sat Mar 23 22:35:02 2013 -0700
     2.3 @@ -95,7 +95,8 @@
     2.4  
     2.5   public:
     2.6    static bool _stack_is_executable;
     2.7 -  static void *dll_load_inner(const char *name);
     2.8 +  static void *dlopen_helper(const char *name, char *ebuf, int ebuflen);
     2.9 +  static void *dll_load_in_vmthread(const char *name, char *ebuf, int ebuflen);
    2.10  
    2.11    static void init_thread_fpu_state();
    2.12    static int  get_fpu_control_word();
     3.1 --- a/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp	Sat Mar 23 10:06:34 2013 -0700
     3.2 +++ b/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp	Sat Mar 23 22:35:02 2013 -0700
     3.3 @@ -46,7 +46,7 @@
     3.4  
     3.5  define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
     3.6  
     3.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     3.8 +// Used on 64 bit platforms for UseCompressedOops base address
     3.9  define_pd_global(uintx, HeapBaseMinAddress,      2*G);
    3.10  
    3.11  #endif // OS_CPU_BSD_X86_VM_GLOBALS_BSD_X86_HPP
     4.1 --- a/src/os_cpu/bsd_zero/vm/globals_bsd_zero.hpp	Sat Mar 23 10:06:34 2013 -0700
     4.2 +++ b/src/os_cpu/bsd_zero/vm/globals_bsd_zero.hpp	Sat Mar 23 22:35:02 2013 -0700
     4.3 @@ -41,7 +41,7 @@
     4.4  define_pd_global(intx,  CompilerThreadStackSize, 0);
     4.5  define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
     4.6  
     4.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     4.8 +// Used on 64 bit platforms for UseCompressedOops base address
     4.9  define_pd_global(uintx, HeapBaseMinAddress,      2*G);
    4.10  
    4.11  #endif // OS_CPU_BSD_ZERO_VM_GLOBALS_BSD_ZERO_HPP
     5.1 --- a/src/os_cpu/linux_sparc/vm/globals_linux_sparc.hpp	Sat Mar 23 10:06:34 2013 -0700
     5.2 +++ b/src/os_cpu/linux_sparc/vm/globals_linux_sparc.hpp	Sat Mar 23 22:35:02 2013 -0700
     5.3 @@ -33,7 +33,7 @@
     5.4  define_pd_global(uintx, JVMInvokeMethodSlack,    12288);
     5.5  define_pd_global(intx, CompilerThreadStackSize,  0);
     5.6  
     5.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     5.8 +// Used on 64 bit platforms for UseCompressedOops base address
     5.9  define_pd_global(uintx, HeapBaseMinAddress,      CONST64(4)*G);
    5.10  
    5.11  #endif // OS_CPU_LINUX_SPARC_VM_GLOBALS_LINUX_SPARC_HPP
     6.1 --- a/src/os_cpu/linux_x86/vm/globals_linux_x86.hpp	Sat Mar 23 10:06:34 2013 -0700
     6.2 +++ b/src/os_cpu/linux_x86/vm/globals_linux_x86.hpp	Sat Mar 23 22:35:02 2013 -0700
     6.3 @@ -44,7 +44,7 @@
     6.4  
     6.5  define_pd_global(uintx,JVMInvokeMethodSlack,     8192);
     6.6  
     6.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     6.8 +// Used on 64 bit platforms for UseCompressedOops base address
     6.9  define_pd_global(uintx,HeapBaseMinAddress,       2*G);
    6.10  
    6.11  #endif // OS_CPU_LINUX_X86_VM_GLOBALS_LINUX_X86_HPP
     7.1 --- a/src/os_cpu/linux_zero/vm/globals_linux_zero.hpp	Sat Mar 23 10:06:34 2013 -0700
     7.2 +++ b/src/os_cpu/linux_zero/vm/globals_linux_zero.hpp	Sat Mar 23 22:35:02 2013 -0700
     7.3 @@ -41,7 +41,7 @@
     7.4  define_pd_global(intx,  CompilerThreadStackSize, 0);
     7.5  define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
     7.6  
     7.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     7.8 +// Used on 64 bit platforms for UseCompressedOops base address
     7.9  define_pd_global(uintx, HeapBaseMinAddress,      2*G);
    7.10  
    7.11  #endif // OS_CPU_LINUX_ZERO_VM_GLOBALS_LINUX_ZERO_HPP
     8.1 --- a/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp	Sat Mar 23 10:06:34 2013 -0700
     8.2 +++ b/src/os_cpu/solaris_sparc/vm/globals_solaris_sparc.hpp	Sat Mar 23 22:35:02 2013 -0700
     8.3 @@ -33,7 +33,7 @@
     8.4  define_pd_global(uintx, JVMInvokeMethodSlack,    12288);
     8.5  define_pd_global(intx, CompilerThreadStackSize,  0);
     8.6  
     8.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     8.8 +// Used on 64 bit platforms for UseCompressedOops base address
     8.9  #ifdef _LP64
    8.10  define_pd_global(uintx, HeapBaseMinAddress,      CONST64(4)*G);
    8.11  #else
     9.1 --- a/src/os_cpu/solaris_x86/vm/globals_solaris_x86.hpp	Sat Mar 23 10:06:34 2013 -0700
     9.2 +++ b/src/os_cpu/solaris_x86/vm/globals_solaris_x86.hpp	Sat Mar 23 22:35:02 2013 -0700
     9.3 @@ -43,7 +43,7 @@
     9.4  
     9.5  define_pd_global(intx, CompilerThreadStackSize,  0);
     9.6  
     9.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
     9.8 +// Used on 64 bit platforms for UseCompressedOops base address
     9.9  define_pd_global(uintx,HeapBaseMinAddress,       256*M);
    9.10  
    9.11  #endif // OS_CPU_SOLARIS_X86_VM_GLOBALS_SOLARIS_X86_HPP
    10.1 --- a/src/os_cpu/windows_x86/vm/globals_windows_x86.hpp	Sat Mar 23 10:06:34 2013 -0700
    10.2 +++ b/src/os_cpu/windows_x86/vm/globals_windows_x86.hpp	Sat Mar 23 22:35:02 2013 -0700
    10.3 @@ -45,7 +45,7 @@
    10.4  
    10.5  define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
    10.6  
    10.7 -// Used on 64 bit platforms for UseCompressedOops base address or CDS
    10.8 +// Used on 64 bit platforms for UseCompressedOops base address
    10.9  define_pd_global(uintx, HeapBaseMinAddress,      2*G);
   10.10  
   10.11  #endif // OS_CPU_WINDOWS_X86_VM_GLOBALS_WINDOWS_X86_HPP
    11.1 --- a/src/share/vm/memory/filemap.cpp	Sat Mar 23 10:06:34 2013 -0700
    11.2 +++ b/src/share/vm/memory/filemap.cpp	Sat Mar 23 22:35:02 2013 -0700
    11.3 @@ -372,7 +372,7 @@
    11.4    // other reserved memory (like the code cache).
    11.5    ReservedSpace rs(size, alignment, false, requested_addr);
    11.6    if (!rs.is_reserved()) {
    11.7 -    fail_continue(err_msg("Unable to reserved shared space at required address " INTPTR_FORMAT, requested_addr));
    11.8 +    fail_continue(err_msg("Unable to reserve shared space at required address " INTPTR_FORMAT, requested_addr));
    11.9      return rs;
   11.10    }
   11.11    // the reserved virtual memory is for mapping class data sharing archive
    12.1 --- a/src/share/vm/memory/metaspace.cpp	Sat Mar 23 10:06:34 2013 -0700
    12.2 +++ b/src/share/vm/memory/metaspace.cpp	Sat Mar 23 22:35:02 2013 -0700
    12.3 @@ -337,27 +337,16 @@
    12.4    // align up to vm allocation granularity
    12.5    byte_size = align_size_up(byte_size, os::vm_allocation_granularity());
    12.6  
    12.7 -  // This allocates memory with mmap.  For DumpSharedspaces, allocate the
    12.8 -  // space at low memory so that other shared images don't conflict.
    12.9 -  // This is the same address as memory needed for UseCompressedOops but
   12.10 -  // compressed oops don't work with CDS (offsets in metadata are wrong), so
   12.11 -  // borrow the same address.
   12.12 +  // This allocates memory with mmap.  For DumpSharedspaces, try to reserve
   12.13 +  // configurable address, generally at the top of the Java heap so other
   12.14 +  // memory addresses don't conflict.
   12.15    if (DumpSharedSpaces) {
   12.16 -    char* shared_base = (char*)HeapBaseMinAddress;
   12.17 +    char* shared_base = (char*)SharedBaseAddress;
   12.18      _rs = ReservedSpace(byte_size, 0, false, shared_base, 0);
   12.19      if (_rs.is_reserved()) {
   12.20 -      assert(_rs.base() == shared_base, "should match");
   12.21 +      assert(shared_base == 0 || _rs.base() == shared_base, "should match");
   12.22      } else {
   12.23 -      // If we are dumping the heap, then allocate a wasted block of address
   12.24 -      // space in order to push the heap to a lower address.  This extra
   12.25 -      // address range allows for other (or larger) libraries to be loaded
   12.26 -      // without them occupying the space required for the shared spaces.
   12.27 -      uintx reserved = 0;
   12.28 -      uintx block_size = 64*1024*1024;
   12.29 -      while (reserved < SharedDummyBlockSize) {
   12.30 -        char* dummy = os::reserve_memory(block_size);
   12.31 -        reserved += block_size;
   12.32 -      }
   12.33 +      // Get a mmap region anywhere if the SharedBaseAddress fails.
   12.34        _rs = ReservedSpace(byte_size);
   12.35      }
   12.36      MetaspaceShared::set_shared_rs(&_rs);
    13.1 --- a/src/share/vm/prims/jvm.cpp	Sat Mar 23 10:06:34 2013 -0700
    13.2 +++ b/src/share/vm/prims/jvm.cpp	Sat Mar 23 22:35:02 2013 -0700
    13.3 @@ -1722,7 +1722,7 @@
    13.4    int i;
    13.5    for (i = 0; i < methods_length; i++) {
    13.6      methodHandle method(THREAD, methods->at(i));
    13.7 -    if (!method->is_initializer()) {
    13.8 +    if (!method->is_initializer() && !method->is_overpass()) {
    13.9        if (!publicOnly || method->is_public()) {
   13.10          ++num_methods;
   13.11        }
   13.12 @@ -1736,7 +1736,7 @@
   13.13    int out_idx = 0;
   13.14    for (i = 0; i < methods_length; i++) {
   13.15      methodHandle method(THREAD, methods->at(i));
   13.16 -    if (!method->is_initializer()) {
   13.17 +    if (!method->is_initializer() && !method->is_overpass()) {
   13.18        if (!publicOnly || method->is_public()) {
   13.19          oop m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL);
   13.20          result->obj_at_put(out_idx, m);
    14.1 --- a/src/share/vm/runtime/globals.hpp	Sat Mar 23 10:06:34 2013 -0700
    14.2 +++ b/src/share/vm/runtime/globals.hpp	Sat Mar 23 22:35:02 2013 -0700
    14.3 @@ -869,6 +869,11 @@
    14.4    diagnostic(bool, PrintNMTStatistics, false,                               \
    14.5            "Print native memory tracking summary data if it is on")          \
    14.6                                                                              \
    14.7 +  diagnostic(bool, AutoShutdownNMT, true,                                   \
    14.8 +          "Automatically shutdown native memory tracking under stress "     \
    14.9 +          "situation. When set to false, native memory tracking tries to "  \
   14.10 +          "stay alive at the expense of JVM performance")                   \
   14.11 +                                                                            \
   14.12    diagnostic(bool, LogCompilation, false,                                   \
   14.13            "Log compilation activity in detail to hotspot.log or LogFile")   \
   14.14                                                                              \
   14.15 @@ -2905,6 +2910,10 @@
   14.16            "if non-zero, start verifying C heap after Nth call to "          \
   14.17            "malloc/realloc/free")                                            \
   14.18                                                                              \
   14.19 +  diagnostic(uintx, MallocMaxTestWords,     0,                              \
   14.20 +          "if non-zero, max # of Words that malloc/realloc can allocate "   \
   14.21 +          "(for testing only)")                                             \
   14.22 +                                                                            \
   14.23    product(intx, TypeProfileWidth,     2,                                    \
   14.24            "number of receiver types to record in call/cast profile")        \
   14.25                                                                              \
   14.26 @@ -3569,8 +3578,9 @@
   14.27    product(uintx, SharedMiscCodeSize,    120*K,                              \
   14.28            "Size of the shared miscellaneous code area (in bytes)")          \
   14.29                                                                              \
   14.30 -  product(uintx, SharedDummyBlockSize, 0,                                   \
   14.31 -          "Size of dummy block used to shift heap addresses (in bytes)")    \
   14.32 +  product(uintx, SharedBaseAddress, LP64_ONLY(32*G)                         \
   14.33 +          NOT_LP64(LINUX_ONLY(2*G) NOT_LINUX(0)),                           \
   14.34 +          "Address to allocate shared memory region for class data")        \
   14.35                                                                              \
   14.36    diagnostic(bool, EnableInvokeDynamic, true,                               \
   14.37            "support JSR 292 (method handles, invokedynamic, "                \
    15.1 --- a/src/share/vm/runtime/os.cpp	Sat Mar 23 10:06:34 2013 -0700
    15.2 +++ b/src/share/vm/runtime/os.cpp	Sat Mar 23 22:35:02 2013 -0700
    15.3 @@ -1,5 +1,5 @@
    15.4  /*
    15.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
    15.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    15.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.8   *
    15.9   * This code is free software; you can redistribute it and/or modify it
   15.10 @@ -80,6 +80,8 @@
   15.11  julong os::free_bytes = 0;          // # of bytes freed
   15.12  #endif
   15.13  
   15.14 +static juint cur_malloc_words = 0;  // current size for MallocMaxTestWords
   15.15 +
   15.16  void os_init_globals() {
   15.17    // Called from init_globals().
   15.18    // See Threads::create_vm() in thread.cpp, and init.cpp.
   15.19 @@ -570,6 +572,26 @@
   15.20  }
   15.21  #endif
   15.22  
   15.23 +//
   15.24 +// This function supports testing of the malloc out of memory
   15.25 +// condition without really running the system out of memory.
   15.26 +//
   15.27 +static u_char* testMalloc(size_t alloc_size) {
   15.28 +  assert(MallocMaxTestWords > 0, "sanity check");
   15.29 +
   15.30 +  if ((cur_malloc_words + (alloc_size / BytesPerWord)) > MallocMaxTestWords) {
   15.31 +    return NULL;
   15.32 +  }
   15.33 +
   15.34 +  u_char* ptr = (u_char*)::malloc(alloc_size);
   15.35 +
   15.36 +  if (ptr != NULL) {
   15.37 +    Atomic::add(((jint) (alloc_size / BytesPerWord)),
   15.38 +                (volatile jint *) &cur_malloc_words);
   15.39 +  }
   15.40 +  return ptr;
   15.41 +}
   15.42 +
   15.43  void* os::malloc(size_t size, MEMFLAGS memflags, address caller) {
   15.44    NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
   15.45    NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
   15.46 @@ -579,11 +601,22 @@
   15.47      // if NULL is returned the calling functions assume out of memory.
   15.48      size = 1;
   15.49    }
   15.50 -  if (size > size + space_before + space_after) { // Check for rollover.
   15.51 +
   15.52 +  const size_t alloc_size = size + space_before + space_after;
   15.53 +
   15.54 +  if (size > alloc_size) { // Check for rollover.
   15.55      return NULL;
   15.56    }
   15.57 +
   15.58    NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap());
   15.59 -  u_char* ptr = (u_char*)::malloc(size + space_before + space_after);
   15.60 +
   15.61 +  u_char* ptr;
   15.62 +
   15.63 +  if (MallocMaxTestWords > 0) {
   15.64 +    ptr = testMalloc(alloc_size);
   15.65 +  } else {
   15.66 +    ptr = (u_char*)::malloc(alloc_size);
   15.67 +  }
   15.68  
   15.69  #ifdef ASSERT
   15.70    if (ptr == NULL) return NULL;
    16.1 --- a/src/share/vm/services/memTracker.cpp	Sat Mar 23 10:06:34 2013 -0700
    16.2 +++ b/src/share/vm/services/memTracker.cpp	Sat Mar 23 22:35:02 2013 -0700
    16.3 @@ -68,6 +68,7 @@
    16.4  volatile jint                   MemTracker::_pooled_recorder_count = 0;
    16.5  volatile unsigned long          MemTracker::_processing_generation = 0;
    16.6  volatile bool                   MemTracker::_worker_thread_idle = false;
    16.7 +volatile bool                   MemTracker::_slowdown_calling_thread = false;
    16.8  debug_only(intx                 MemTracker::_main_thread_tid = 0;)
    16.9  NOT_PRODUCT(volatile jint       MemTracker::_pending_recorder_count = 0;)
   16.10  
   16.11 @@ -364,6 +365,12 @@
   16.12      }
   16.13  
   16.14      if (thread != NULL) {
   16.15 +      // slow down all calling threads except NMT worker thread, so it
   16.16 +      // can catch up.
   16.17 +      if (_slowdown_calling_thread && thread != _worker_thread) {
   16.18 +        os::yield_all();
   16.19 +      }
   16.20 +
   16.21        if (thread->is_Java_thread() && ((JavaThread*)thread)->is_safepoint_visible()) {
   16.22          JavaThread*      java_thread = (JavaThread*)thread;
   16.23          JavaThreadState  state = java_thread->thread_state();
   16.24 @@ -442,6 +449,7 @@
   16.25  #define MAX_SAFEPOINTS_TO_SKIP     128
   16.26  #define SAFE_SEQUENCE_THRESHOLD    30
   16.27  #define HIGH_GENERATION_THRESHOLD  60
   16.28 +#define MAX_RECORDER_THREAD_RATIO  30
   16.29  
   16.30  void MemTracker::sync() {
   16.31    assert(_tracking_level > NMT_off, "NMT is not enabled");
   16.32 @@ -487,6 +495,13 @@
   16.33          pending_recorders = _global_recorder;
   16.34          _global_recorder = NULL;
   16.35        }
   16.36 +
   16.37 +      // see if NMT has too many outstanding recorder instances, it usually
   16.38 +      // means that worker thread is lagging behind in processing them.
   16.39 +      if (!AutoShutdownNMT) {
   16.40 +        _slowdown_calling_thread = (MemRecorder::_instance_count > MAX_RECORDER_THREAD_RATIO * _thread_count);
   16.41 +      }
   16.42 +
   16.43        // check _worker_thread with lock to avoid racing condition
   16.44        if (_worker_thread != NULL) {
   16.45          _worker_thread->at_sync_point(pending_recorders, InstanceKlass::number_of_instance_classes());
    17.1 --- a/src/share/vm/services/memTracker.hpp	Sat Mar 23 10:06:34 2013 -0700
    17.2 +++ b/src/share/vm/services/memTracker.hpp	Sat Mar 23 22:35:02 2013 -0700
    17.3 @@ -84,6 +84,7 @@
    17.4     static inline bool baseline() { return false; }
    17.5     static inline bool has_baseline() { return false; }
    17.6  
    17.7 +   static inline void set_autoShutdown(bool value) { }
    17.8     static void shutdown(ShutdownReason reason) { }
    17.9     static inline bool shutdown_in_progress() {  }
   17.10     static bool print_memory_usage(BaselineOutputer& out, size_t unit,
   17.11 @@ -238,6 +239,16 @@
   17.12    // if native memory tracking tracks callsite
   17.13    static inline bool track_callsite() { return _tracking_level == NMT_detail; }
   17.14  
   17.15 +  // NMT automatically shuts itself down under extreme situation by default.
   17.16 +  // When the value is set to false,  NMT will try its best to stay alive,
   17.17 +  // even it has to slow down VM.
   17.18 +  static inline void set_autoShutdown(bool value) {
   17.19 +    AutoShutdownNMT = value;
   17.20 +    if (AutoShutdownNMT && _slowdown_calling_thread) {
   17.21 +      _slowdown_calling_thread = false;
   17.22 +    }
   17.23 +  }
   17.24 +
   17.25    // shutdown native memory tracking capability. Native memory tracking
   17.26    // can be shutdown by VM when it encounters low memory scenarios.
   17.27    // Memory tracker should gracefully shutdown itself, and preserve the
   17.28 @@ -507,6 +518,10 @@
   17.29    // although NMT is still procesing current generation, but
   17.30    // there is not more recorder to process, set idle state
   17.31    static volatile bool             _worker_thread_idle;
   17.32 +
   17.33 +  // if NMT should slow down calling thread to allow
   17.34 +  // worker thread to catch up
   17.35 +  static volatile bool             _slowdown_calling_thread;
   17.36  };
   17.37  
   17.38  #endif // !INCLUDE_NMT
    18.1 --- a/src/share/vm/services/nmtDCmd.cpp	Sat Mar 23 10:06:34 2013 -0700
    18.2 +++ b/src/share/vm/services/nmtDCmd.cpp	Sat Mar 23 22:35:02 2013 -0700
    18.3 @@ -49,6 +49,9 @@
    18.4    _shutdown("shutdown", "request runtime to shutdown itself and free the " \
    18.5              "memory used by runtime.",
    18.6              "BOOLEAN", false, "false"),
    18.7 +  _auto_shutdown("autoShutdown", "automatically shutdown itself under "    \
    18.8 +            "stress situation",
    18.9 +            "BOOLEAN", true, "true"),
   18.10  #ifndef PRODUCT
   18.11    _debug("debug", "print tracker statistics. Debug only, not thread safe", \
   18.12              "BOOLEAN", false, "false"),
   18.13 @@ -61,6 +64,7 @@
   18.14    _dcmdparser.add_dcmd_option(&_summary_diff);
   18.15    _dcmdparser.add_dcmd_option(&_detail_diff);
   18.16    _dcmdparser.add_dcmd_option(&_shutdown);
   18.17 +  _dcmdparser.add_dcmd_option(&_auto_shutdown);
   18.18  #ifndef PRODUCT
   18.19    _dcmdparser.add_dcmd_option(&_debug);
   18.20  #endif
   18.21 @@ -84,17 +88,19 @@
   18.22    }
   18.23  
   18.24    int nopt = 0;
   18.25 -  if(_summary.is_set() && _summary.value()) { ++nopt; }
   18.26 -  if(_detail.is_set() && _detail.value()) { ++nopt; }
   18.27 -  if(_baseline.is_set() && _baseline.value()) { ++nopt; }
   18.28 -  if(_summary_diff.is_set() && _summary_diff.value()) { ++nopt; }
   18.29 -  if(_detail_diff.is_set() && _detail_diff.value()) { ++nopt; }
   18.30 -  if(_shutdown.is_set() && _shutdown.value()) { ++nopt; }
   18.31 +  if (_summary.is_set() && _summary.value()) { ++nopt; }
   18.32 +  if (_detail.is_set() && _detail.value()) { ++nopt; }
   18.33 +  if (_baseline.is_set() && _baseline.value()) { ++nopt; }
   18.34 +  if (_summary_diff.is_set() && _summary_diff.value()) { ++nopt; }
   18.35 +  if (_detail_diff.is_set() && _detail_diff.value()) { ++nopt; }
   18.36 +  if (_shutdown.is_set() && _shutdown.value()) { ++nopt; }
   18.37 +  if (_auto_shutdown.is_set()) { ++nopt; }
   18.38 +
   18.39  #ifndef PRODUCT
   18.40 -  if(_debug.is_set() && _debug.value()) { ++nopt; }
   18.41 +  if (_debug.is_set() && _debug.value()) { ++nopt; }
   18.42  #endif
   18.43  
   18.44 -  if(nopt > 1) {
   18.45 +  if (nopt > 1) {
   18.46        output()->print_cr("At most one of the following option can be specified: " \
   18.47          "summary, detail, baseline, summary.diff, detail.diff, shutdown"
   18.48  #ifndef PRODUCT
   18.49 @@ -156,6 +162,8 @@
   18.50      MemTracker::shutdown(MemTracker::NMT_shutdown_user);
   18.51      output()->print_cr("Shutdown is in progress, it will take a few moments to " \
   18.52        "completely shutdown");
   18.53 +  } else if (_auto_shutdown.is_set()) {
   18.54 +    MemTracker::set_autoShutdown(_auto_shutdown.value());
   18.55    } else {
   18.56      ShouldNotReachHere();
   18.57      output()->print_cr("Unknown command");
    19.1 --- a/src/share/vm/services/nmtDCmd.hpp	Sat Mar 23 10:06:34 2013 -0700
    19.2 +++ b/src/share/vm/services/nmtDCmd.hpp	Sat Mar 23 22:35:02 2013 -0700
    19.3 @@ -39,6 +39,7 @@
    19.4    DCmdArgument<bool>  _summary_diff;
    19.5    DCmdArgument<bool>  _detail_diff;
    19.6    DCmdArgument<bool>  _shutdown;
    19.7 +  DCmdArgument<bool>  _auto_shutdown;
    19.8  #ifndef PRODUCT
    19.9    DCmdArgument<bool>  _debug;
   19.10  #endif
    20.1 --- a/test/runtime/6878713/Test6878713.sh	Sat Mar 23 10:06:34 2013 -0700
    20.2 +++ b/test/runtime/6878713/Test6878713.sh	Sat Mar 23 22:35:02 2013 -0700
    20.3 @@ -1,10 +1,38 @@
    20.4  #!/bin/sh
    20.5  
    20.6 +# 
    20.7 +#  Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
    20.8 +#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    20.9 +# 
   20.10 +#  This code is free software; you can redistribute it and/or modify it
   20.11 +#  under the terms of the GNU General Public License version 2 only, as
   20.12 +#  published by the Free Software Foundation.
   20.13 +# 
   20.14 +#  This code is distributed in the hope that it will be useful, but WITHOUT
   20.15 +#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   20.16 +#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   20.17 +#  version 2 for more details (a copy is included in the LICENSE file that
   20.18 +#  accompanied this code).
   20.19 +# 
   20.20 +#  You should have received a copy of the GNU General Public License version
   20.21 +#  2 along with this work; if not, write to the Free Software Foundation,
   20.22 +#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20.23 +# 
   20.24 +#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20.25 +#  or visit www.oracle.com if you need additional information or have any
   20.26 +#  questions.
   20.27 +# 
   20.28 +
   20.29 + 
   20.30 +
   20.31  ##
   20.32  ## @test
   20.33  ## @bug 6878713
   20.34 +## @bug 7030610
   20.35 +## @bug 7037122
   20.36 +## @bug 7123945
   20.37  ## @summary Verifier heap corruption, relating to backward jsrs
   20.38 -## @run shell/timeout=120 Test6878713.sh
   20.39 +## @run shell Test6878713.sh
   20.40  ##
   20.41  
   20.42  if [ "${TESTSRC}" = "" ]
   20.43 @@ -49,23 +77,98 @@
   20.44      ;;
   20.45  esac
   20.46  
   20.47 -JEMMYPATH=${CPAPPEND}
   20.48 -CLASSPATH=.${PS}${TESTCLASSES}${PS}${JEMMYPATH} ; export CLASSPATH
   20.49 -
   20.50 -THIS_DIR=`pwd`
   20.51 +CLASSPATH=.${PS}${TESTCLASSES} ; export CLASSPATH
   20.52  
   20.53  ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -version
   20.54  
   20.55 -${TESTJAVA}${FS}bin${FS}jar xvf ${TESTSRC}${FS}testcase.jar
   20.56 +TARGET_CLASS=OOMCrashClass1960_2
   20.57  
   20.58 -${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} OOMCrashClass1960_2 > test.out 2>&1
   20.59 +echo "INFO: extracting the target class."
   20.60 +${TESTJAVA}${FS}bin${FS}jar xvf \
   20.61 +    ${TESTSRC}${FS}testcase.jar ${TARGET_CLASS}.class
   20.62  
   20.63 -if [ -s core -o -s "hs_*.log" ]
   20.64 -then
   20.65 -    cat hs*.log
   20.66 -    echo "Test Failed"
   20.67 -    exit 1
   20.68 +# remove any hs_err_pid that might exist here
   20.69 +rm -f hs_err_pid*.log
   20.70 +
   20.71 +echo "INFO: checking for 32-bit versus 64-bit VM."
   20.72 +${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -version 2>&1 \
   20.73 +    | grep "64-Bit [^ ][^ ]* VM" > /dev/null 2>&1
   20.74 +status="$?"
   20.75 +if [ "$status" = 0 ]; then
   20.76 +    echo "INFO: testing a 64-bit VM."
   20.77 +    is_64_bit=true
   20.78  else
   20.79 -    echo "Test Passed"
   20.80 -    exit 0
   20.81 +    echo "INFO: testing a 32-bit VM."
   20.82  fi
   20.83 +
   20.84 +if [ "$is_64_bit" = true ]; then
   20.85 +    # limit is 768MB in 8-byte words (1024 * 1024 * 768 / 8) == 100663296
   20.86 +    MALLOC_MAX=100663296
   20.87 +else
   20.88 +    # limit is 768MB in 4-byte words (1024 * 1024 * 768 / 4) == 201326592
   20.89 +    MALLOC_MAX=201326592
   20.90 +fi
   20.91 +echo "INFO: MALLOC_MAX=$MALLOC_MAX"
   20.92 +
   20.93 +echo "INFO: executing the target class."
   20.94 +# -XX:+PrintCommandLineFlags for debugging purposes
   20.95 +# -XX:+IgnoreUnrecognizedVMOptions so test will run on a VM without
   20.96 +#     the new -XX:MallocMaxTestWords option
   20.97 +# -XX:+UnlockDiagnosticVMOptions so we can use -XX:MallocMaxTestWords
   20.98 +# -XX:MallocMaxTestWords limits malloc to $MALLOC_MAX
   20.99 +${TESTJAVA}${FS}bin${FS}java \
  20.100 +    -XX:+PrintCommandLineFlags \
  20.101 +    -XX:+IgnoreUnrecognizedVMOptions \
  20.102 +    -XX:+UnlockDiagnosticVMOptions \
  20.103 +    -XX:MallocMaxTestWords=$MALLOC_MAX \
  20.104 +    ${TESTVMOPTS} ${TARGET_CLASS} > test.out 2>&1
  20.105 +
  20.106 +echo "INFO: begin contents of test.out:"
  20.107 +cat test.out
  20.108 +echo "INFO: end contents of test.out."
  20.109 +
  20.110 +echo "INFO: checking for memory allocation error message."
  20.111 +# We are looking for this specific memory allocation failure mesg so
  20.112 +# we know we exercised the right allocation path with the test class:
  20.113 +MESG1="Native memory allocation (malloc) failed to allocate 25696531[0-9][0-9] bytes"
  20.114 +grep "$MESG1" test.out
  20.115 +status="$?"
  20.116 +if [ "$status" = 0 ]; then
  20.117 +    echo "INFO: found expected memory allocation error message."
  20.118 +else
  20.119 +    echo "INFO: did not find expected memory allocation error message."
  20.120 +
  20.121 +    # If we didn't find MESG1 above, then there are several scenarios:
  20.122 +    # 1) -XX:MallocMaxTestWords is not supported by the current VM and we
  20.123 +    #    didn't fail TARGET_CLASS's memory allocation attempt; instead
  20.124 +    #    we failed to find TARGET_CLASS's main() method. The TARGET_CLASS
  20.125 +    #    is designed to provoke a memory allocation failure during class
  20.126 +    #    loading; we actually don't care about running the class which is
  20.127 +    #    why it doesn't have a main() method.
  20.128 +    # 2) we failed a memory allocation, but not the one we were looking
  20.129 +    #    so it might be that TARGET_CLASS no longer tickles the same
  20.130 +    #    memory allocation code path
  20.131 +    # 3) TARGET_CLASS reproduces the failure mode (SIGSEGV) fixed by
  20.132 +    #    6878713 because the test is running on a pre-fix VM.
  20.133 +    echo "INFO: checking for no main() method message."
  20.134 +    MESG2="Error: Main method not found in class"
  20.135 +    grep "$MESG2" test.out
  20.136 +    status="$?"
  20.137 +    if [ "$status" = 0 ]; then
  20.138 +        echo "INFO: found no main() method message."
  20.139 +    else
  20.140 +        echo "FAIL: did not find no main() method message."
  20.141 +        # status is non-zero for exit below
  20.142 +
  20.143 +        if [ -s hs_err_pid*.log ]; then
  20.144 +            echo "INFO: begin contents of hs_err_pid file:"
  20.145 +            cat hs_err_pid*.log
  20.146 +            echo "INFO: end contents of hs_err_pid file."
  20.147 +        fi
  20.148 +    fi
  20.149 +fi
  20.150 +
  20.151 +if [ "$status" = 0 ]; then
  20.152 +    echo "PASS: test found one of the expected messages."
  20.153 +fi
  20.154 +exit "$status"
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/test/runtime/8010389/VMThreadDlopen.java	Sat Mar 23 22:35:02 2013 -0700
    21.3 @@ -0,0 +1,44 @@
    21.4 +/*
    21.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    21.7 + *
    21.8 + * This code is free software; you can redistribute it and/or modify it
    21.9 + * under the terms of the GNU General Public License version 2 only, as
   21.10 + * published by the Free Software Foundation.
   21.11 + *
   21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   21.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   21.15 + * version 2 for more details (a copy is included in the LICENSE file that
   21.16 + * accompanied this code).
   21.17 + *
   21.18 + * You should have received a copy of the GNU General Public License version
   21.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   21.21 + *
   21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   21.23 + * or visit www.oracle.com if you need additional information or have any
   21.24 + * questions.
   21.25 + */
   21.26 +
   21.27 +import java.io.File;
   21.28 +
   21.29 +/*
   21.30 + * @test
   21.31 + * @key regression
   21.32 + * @bug 8010389
   21.33 + * @run main/othervm -Djava.library.path=. VMThreadDlopen
   21.34 + */
   21.35 +
   21.36 +public class VMThreadDlopen {
   21.37 +    public static void main(String[] args) throws Exception {
   21.38 +        File file = new File("libbroken.so");
   21.39 +        file.createNewFile();
   21.40 +        try {
   21.41 +            System.loadLibrary("broken");
   21.42 +        } catch (UnsatisfiedLinkError e) {
   21.43 +            e.printStackTrace();
   21.44 +            // expected
   21.45 +        }
   21.46 +    }
   21.47 +}
    22.1 --- a/test/runtime/CommandLine/BooleanFlagWithInvalidValue.java	Sat Mar 23 10:06:34 2013 -0700
    22.2 +++ b/test/runtime/CommandLine/BooleanFlagWithInvalidValue.java	Sat Mar 23 22:35:02 2013 -0700
    22.3 @@ -33,17 +33,17 @@
    22.4  public class BooleanFlagWithInvalidValue {
    22.5    public static void main(String[] args) throws Exception {
    22.6      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    22.7 -        "-XX:+UseLargePages=8", "-version");
    22.8 +        "-XX:+PrintWarnings=8", "-version");
    22.9  
   22.10      OutputAnalyzer output = new OutputAnalyzer(pb.start());
   22.11 -    output.shouldContain("Improperly specified VM option 'UseLargePages=8'");
   22.12 +    output.shouldContain("Improperly specified VM option 'PrintWarnings=8'");
   22.13      output.shouldHaveExitValue(1);
   22.14  
   22.15      pb = ProcessTools.createJavaProcessBuilder(
   22.16 -        "-XX:-UseLargePages=8", "-version");
   22.17 +        "-XX:-PrintWarnings=8", "-version");
   22.18  
   22.19      output = new OutputAnalyzer(pb.start());
   22.20 -    output.shouldContain("Improperly specified VM option 'UseLargePages=8'");
   22.21 +    output.shouldContain("Improperly specified VM option 'PrintWarnings=8'");
   22.22      output.shouldHaveExitValue(1);
   22.23    }
   22.24  }
    23.1 --- a/test/runtime/CommandLine/FlagWithInvalidValue.java	Sat Mar 23 10:06:34 2013 -0700
    23.2 +++ b/test/runtime/CommandLine/FlagWithInvalidValue.java	Sat Mar 23 22:35:02 2013 -0700
    23.3 @@ -33,10 +33,10 @@
    23.4  public class FlagWithInvalidValue {
    23.5    public static void main(String[] args) throws Exception {
    23.6      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    23.7 -        "-XX:ObjectAlignmentInBytes=v", "-version");
    23.8 +        "-XX:MaxRAMFraction=v", "-version");
    23.9  
   23.10      OutputAnalyzer output = new OutputAnalyzer(pb.start());
   23.11 -    output.shouldContain("Improperly specified VM option 'ObjectAlignmentInBytes=v'");
   23.12 +    output.shouldContain("Improperly specified VM option 'MaxRAMFraction=v'");
   23.13      output.shouldHaveExitValue(1);
   23.14    }
   23.15  }
    24.1 --- a/test/runtime/CommandLine/NonBooleanFlagWithInvalidBooleanPrefix.java	Sat Mar 23 10:06:34 2013 -0700
    24.2 +++ b/test/runtime/CommandLine/NonBooleanFlagWithInvalidBooleanPrefix.java	Sat Mar 23 22:35:02 2013 -0700
    24.3 @@ -33,17 +33,17 @@
    24.4  public class NonBooleanFlagWithInvalidBooleanPrefix {
    24.5    public static void main(String[] args) throws Exception {
    24.6      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    24.7 -        "-XX:-ObjectAlignmentInBytes=16", "-version");
    24.8 +        "-XX:-MaxRAMFraction=16", "-version");
    24.9  
   24.10      OutputAnalyzer output = new OutputAnalyzer(pb.start());
   24.11 -    output.shouldContain("Unexpected +/- setting in VM option 'ObjectAlignmentInBytes=16'");
   24.12 +    output.shouldContain("Unexpected +/- setting in VM option 'MaxRAMFraction=16'");
   24.13      output.shouldHaveExitValue(1);
   24.14  
   24.15      pb = ProcessTools.createJavaProcessBuilder(
   24.16 -        "-XX:+ObjectAlignmentInBytes=16", "-version");
   24.17 +        "-XX:+MaxRAMFraction=16", "-version");
   24.18  
   24.19      output = new OutputAnalyzer(pb.start());
   24.20 -    output.shouldContain("Unexpected +/- setting in VM option 'ObjectAlignmentInBytes=16'");
   24.21 +    output.shouldContain("Unexpected +/- setting in VM option 'MaxRAMFraction=16'");
   24.22      output.shouldHaveExitValue(1);
   24.23  
   24.24    }
    25.1 --- a/test/runtime/NMT/BaselineWithParameter.java	Sat Mar 23 10:06:34 2013 -0700
    25.2 +++ b/test/runtime/NMT/BaselineWithParameter.java	Sat Mar 23 22:35:02 2013 -0700
    25.3 @@ -43,7 +43,7 @@
    25.4  
    25.5      // Run 'jcmd <pid> VM.native_memory baseline=false'
    25.6      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline=false"});
    25.7 -    pb.start();
    25.8 +    pb.start().waitFor();
    25.9  
   25.10      // Run 'jcmd <pid> VM.native_memory summary=false'
   25.11      pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary=false"});

mercurial