diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp index 2fb9de039bcf4f942e5f0f96b7f1fc3869ca401c..824ba88aeb129ad3d1cd541f26e719f5584e2e22 100644 --- a/src/share/vm/classfile/classLoader.cpp +++ b/src/share/vm/classfile/classLoader.cpp @@ -1249,6 +1249,7 @@ void ClassLoader::compile_the_world() { } int ClassLoader::_compile_the_world_counter = 0; +static int _codecache_sweep_counter = 0; void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { int len = (int)strlen(name); @@ -1293,6 +1294,13 @@ void ClassLoader::compile_the_world_in(char* name, Handle loader, TRAPS) { for (int n = 0; n < k->methods()->length(); n++) { methodHandle m (THREAD, methodOop(k->methods()->obj_at(n))); if (CompilationPolicy::canBeCompiled(m)) { + + if (++_codecache_sweep_counter == CompileTheWorldSafepointInterval) { + // Give sweeper a chance to keep up with CTW + VM_ForceSafepoint op; + VMThread::execute(&op); + _codecache_sweep_counter = 0; + } // Force compilation CompileBroker::compile_method(m, InvocationEntryBci, methodHandle(), 0, "CTW", THREAD); diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp index e86b46a693d0456f8cbc3e6dda8ea3e9c737be49..499fba2f1beb279b367a4839347a9190977049ef 100644 --- a/src/share/vm/runtime/arguments.cpp +++ b/src/share/vm/runtime/arguments.cpp @@ -2815,6 +2815,15 @@ jint Arguments::parse(const JavaVMInitArgs* args) { DebugNonSafepoints = true; } +#ifndef PRODUCT + if (CompileTheWorld) { + // Force NmethodSweeper to sweep whole CodeCache each time. + if (FLAG_IS_DEFAULT(NmethodSweepFraction)) { + NmethodSweepFraction = 1; + } + } +#endif + if (PrintCommandLineFlags) { CommandLineFlags::printSetFlags(); } diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index 6eac915cf9166f6f9e59e00aee69caf601d90728..01ebb49f935e17eed05ad52b7dc7d923db6df5f7 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -2447,6 +2447,9 @@ class CommandLineFlags { notproduct(bool, CompileTheWorldIgnoreInitErrors, false, \ "Compile all methods although class initializer failed") \ \ + notproduct(intx, CompileTheWorldSafepointInterval, 100, \ + "Force a safepoint every n compiles so sweeper can keep up") \ + \ develop(bool, TraceIterativeGVN, false, \ "Print progress during Iterative Global Value Numbering") \ \