6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong

Thu, 07 Oct 2010 08:06:06 -0700

author
coleenp
date
Thu, 07 Oct 2010 08:06:06 -0700
changeset 2222
b6aedd1acdc0
parent 2221
644f98c78e33
child 2224
7491c8b96111

6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
Summary: min_stack_allowed is a compile time constant and Stack*Pages are settable
Reviewed-by: dholmes, kvn

src/cpu/x86/vm/methodHandles_x86.cpp file | annotate | diff | comparison | revisions
src/os/linux/vm/os_linux.cpp file | annotate | diff | comparison | revisions
src/os/solaris/vm/os_solaris.cpp file | annotate | diff | comparison | revisions
src/os/windows/vm/os_windows.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/arguments.cpp file | annotate | diff | comparison | revisions
src/share/vm/utilities/exceptions.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/cpu/x86/vm/methodHandles_x86.cpp	Mon Oct 04 10:08:29 2010 -0700
     1.2 +++ b/src/cpu/x86/vm/methodHandles_x86.cpp	Thu Oct 07 08:06:06 2010 -0700
     1.3 @@ -346,7 +346,7 @@
     1.4      if (stack_dump_count > 64)  stack_dump_count = 48;
     1.5      for (i = 0; i < stack_dump_count; i += 4) {
     1.6        printf(" dump at SP[%d] "INTPTR_FORMAT": "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT"\n",
     1.7 -             i, &entry_sp[i+0], entry_sp[i+0], entry_sp[i+1], entry_sp[i+2], entry_sp[i+3]);
     1.8 +             i, (intptr_t)&entry_sp[i+0], entry_sp[i+0], entry_sp[i+1], entry_sp[i+2], entry_sp[i+3]);
     1.9      }
    1.10      print_method_handle(mh);
    1.11    }
     2.1 --- a/src/os/linux/vm/os_linux.cpp	Mon Oct 04 10:08:29 2010 -0700
     2.2 +++ b/src/os/linux/vm/os_linux.cpp	Thu Oct 07 08:06:06 2010 -0700
     2.3 @@ -827,8 +827,10 @@
     2.4  
     2.5        switch (thr_type) {
     2.6        case os::java_thread:
     2.7 -        // Java threads use ThreadStackSize which default value can be changed with the flag -Xss
     2.8 -        if (JavaThread::stack_size_at_create() > 0) stack_size = JavaThread::stack_size_at_create();
     2.9 +        // Java threads use ThreadStackSize which default value can be
    2.10 +        // changed with the flag -Xss
    2.11 +        assert (JavaThread::stack_size_at_create() > 0, "this should be set");
    2.12 +        stack_size = JavaThread::stack_size_at_create();
    2.13          break;
    2.14        case os::compiler_thread:
    2.15          if (CompilerThreadStackSize > 0) {
    2.16 @@ -3922,12 +3924,21 @@
    2.17    Linux::signal_sets_init();
    2.18    Linux::install_signal_handlers();
    2.19  
    2.20 +  // Check minimum allowable stack size for thread creation and to initialize
    2.21 +  // the java system classes, including StackOverflowError - depends on page
    2.22 +  // size.  Add a page for compiler2 recursion in main thread.
    2.23 +  // Add in 2*BytesPerWord times page size to account for VM stack during
    2.24 +  // class initialization depending on 32 or 64 bit VM.
    2.25 +  os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
    2.26 +            (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
    2.27 +                    2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::page_size());
    2.28 +
    2.29    size_t threadStackSizeInBytes = ThreadStackSize * K;
    2.30    if (threadStackSizeInBytes != 0 &&
    2.31 -      threadStackSizeInBytes < Linux::min_stack_allowed) {
    2.32 +      threadStackSizeInBytes < os::Linux::min_stack_allowed) {
    2.33          tty->print_cr("\nThe stack size specified is too small, "
    2.34                        "Specify at least %dk",
    2.35 -                      Linux::min_stack_allowed / K);
    2.36 +                      os::Linux::min_stack_allowed/ K);
    2.37          return JNI_ERR;
    2.38    }
    2.39  
     3.1 --- a/src/os/solaris/vm/os_solaris.cpp	Mon Oct 04 10:08:29 2010 -0700
     3.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Thu Oct 07 08:06:06 2010 -0700
     3.3 @@ -4878,18 +4878,17 @@
     3.4    // Check minimum allowable stack size for thread creation and to initialize
     3.5    // the java system classes, including StackOverflowError - depends on page
     3.6    // size.  Add a page for compiler2 recursion in main thread.
     3.7 -  // Add in BytesPerWord times page size to account for VM stack during
     3.8 +  // Add in 2*BytesPerWord times page size to account for VM stack during
     3.9    // class initialization depending on 32 or 64 bit VM.
    3.10 -  guarantee((Solaris::min_stack_allowed >=
    3.11 -    (StackYellowPages+StackRedPages+StackShadowPages+BytesPerWord
    3.12 -     COMPILER2_PRESENT(+1)) * page_size),
    3.13 -    "need to increase Solaris::min_stack_allowed on this platform");
    3.14 +  os::Solaris::min_stack_allowed = MAX2(os::Solaris::min_stack_allowed,
    3.15 +            (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
    3.16 +                    2*BytesPerWord COMPILER2_PRESENT(+1)) * page_size);
    3.17  
    3.18    size_t threadStackSizeInBytes = ThreadStackSize * K;
    3.19    if (threadStackSizeInBytes != 0 &&
    3.20 -    threadStackSizeInBytes < Solaris::min_stack_allowed) {
    3.21 +    threadStackSizeInBytes < os::Solaris::min_stack_allowed) {
    3.22      tty->print_cr("\nThe stack size specified is too small, Specify at least %dk",
    3.23 -                  Solaris::min_stack_allowed/K);
    3.24 +                  os::Solaris::min_stack_allowed/K);
    3.25      return JNI_ERR;
    3.26    }
    3.27  
     4.1 --- a/src/os/windows/vm/os_windows.cpp	Mon Oct 04 10:08:29 2010 -0700
     4.2 +++ b/src/os/windows/vm/os_windows.cpp	Thu Oct 07 08:06:06 2010 -0700
     4.3 @@ -3311,7 +3311,6 @@
     4.4    }
     4.5  }
     4.6  
     4.7 -
     4.8  // this is called _after_ the global arguments have been parsed
     4.9  jint os::init_2(void) {
    4.10    // Allocate a single page and mark it as readable for safepoint polling
    4.11 @@ -3390,6 +3389,21 @@
    4.12      actual_reserve_size = default_reserve_size;
    4.13    }
    4.14  
    4.15 +  // Check minimum allowable stack size for thread creation and to initialize
    4.16 +  // the java system classes, including StackOverflowError - depends on page
    4.17 +  // size.  Add a page for compiler2 recursion in main thread.
    4.18 +  // Add in 2*BytesPerWord times page size to account for VM stack during
    4.19 +  // class initialization depending on 32 or 64 bit VM.
    4.20 +  size_t min_stack_allowed =
    4.21 +            (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
    4.22 +            2*BytesPerWord COMPILER2_PRESENT(+1)) * os::vm_page_size();
    4.23 +  if (actual_reserve_size < min_stack_allowed) {
    4.24 +    tty->print_cr("\nThe stack size specified is too small, "
    4.25 +                  "Specify at least %dk",
    4.26 +                  min_stack_allowed / K);
    4.27 +    return JNI_ERR;
    4.28 +  }
    4.29 +
    4.30    JavaThread::set_stack_size_at_create(stack_commit_size);
    4.31  
    4.32    // Calculate theoretical max. size of Threads to guard gainst artifical
     5.1 --- a/src/share/vm/runtime/arguments.cpp	Mon Oct 04 10:08:29 2010 -0700
     5.2 +++ b/src/share/vm/runtime/arguments.cpp	Thu Oct 07 08:06:06 2010 -0700
     5.3 @@ -1663,7 +1663,8 @@
     5.4    bool status = true;
     5.5    status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages");
     5.6    status = status && verify_min_value(StackRedPages, 1, "StackRedPages");
     5.7 -  status = status && verify_min_value(StackShadowPages, 1, "StackShadowPages");
     5.8 +  // greater stack shadow pages can't generate instruction to bang stack
     5.9 +  status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages");
    5.10    return status;
    5.11  }
    5.12  
     6.1 --- a/src/share/vm/utilities/exceptions.cpp	Mon Oct 04 10:08:29 2010 -0700
     6.2 +++ b/src/share/vm/utilities/exceptions.cpp	Thu Oct 07 08:06:06 2010 -0700
     6.3 @@ -61,6 +61,18 @@
     6.4     ShouldNotReachHere();
     6.5    }
     6.6  
     6.7 +#ifdef ASSERT
     6.8 +  // Check for trying to throw stack overflow before initialization is complete
     6.9 +  // to prevent infinite recursion trying to initialize stack overflow without
    6.10 +  // adequate stack space.
    6.11 +  // This can happen with stress testing a large value of StackShadowPages
    6.12 +  if (h_exception()->klass() == SystemDictionary::StackOverflowError_klass()) {
    6.13 +    instanceKlass* ik = instanceKlass::cast(h_exception->klass());
    6.14 +    assert(ik->is_initialized(),
    6.15 +           "need to increase min_stack_allowed calculation");
    6.16 +  }
    6.17 +#endif // ASSERT
    6.18 +
    6.19    if (thread->is_VM_thread()
    6.20        || thread->is_Compiler_thread() ) {
    6.21      // We do not care what kind of exception we get for the vm-thread or a thread which
    6.22 @@ -91,7 +103,6 @@
    6.23      thread->set_pending_exception(Universe::vm_exception(), file, line);
    6.24      return true;
    6.25    }
    6.26 -
    6.27    return false;
    6.28  }
    6.29  
    6.30 @@ -193,6 +204,7 @@
    6.31      klassOop k = SystemDictionary::StackOverflowError_klass();
    6.32      oop e = instanceKlass::cast(k)->allocate_instance(CHECK);
    6.33      exception = Handle(THREAD, e);  // fill_in_stack trace does gc
    6.34 +    assert(instanceKlass::cast(k)->is_initialized(), "need to increase min_stack_allowed calculation");
    6.35      if (StackTraceInThrowable) {
    6.36        java_lang_Throwable::fill_in_stack_trace(exception);
    6.37      }

mercurial