comparison src/share/vm/compiler/compileBroker.cpp @ 10408:836a62f43af9

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 10:45:56 +0200
parents a323a9e20f9d f2110083203d
children cefad50507d8
comparison
equal deleted inserted replaced
10086:e0fb8a213650 10408:836a62f43af9
1 /* 1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
41 #include "runtime/interfaceSupport.hpp" 41 #include "runtime/interfaceSupport.hpp"
42 #include "runtime/javaCalls.hpp" 42 #include "runtime/javaCalls.hpp"
43 #include "runtime/os.hpp" 43 #include "runtime/os.hpp"
44 #include "runtime/sharedRuntime.hpp" 44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/sweeper.hpp" 45 #include "runtime/sweeper.hpp"
46 #include "trace/tracing.hpp"
46 #include "utilities/dtrace.hpp" 47 #include "utilities/dtrace.hpp"
47 #include "utilities/events.hpp" 48 #include "utilities/events.hpp"
48 #ifdef COMPILER1 49 #ifdef COMPILER1
49 #include "c1/c1_Compiler.hpp" 50 #include "c1/c1_Compiler.hpp"
50 #endif 51 #endif
66 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin, 67 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin,
67 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t); 68 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t);
68 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end, 69 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end,
69 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t, bool); 70 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t, bool);
70 71
71 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method, comp_name) \ 72 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
72 { \ 73 { \
73 Symbol* klass_name = (method)->klass_name(); \ 74 Symbol* klass_name = (method)->klass_name(); \
74 Symbol* name = (method)->name(); \ 75 Symbol* name = (method)->name(); \
75 Symbol* signature = (method)->signature(); \ 76 Symbol* signature = (method)->signature(); \
76 HS_DTRACE_PROBE8(hotspot, method__compile__begin, \ 77 HS_DTRACE_PROBE8(hotspot, method__compile__begin, \
78 klass_name->bytes(), klass_name->utf8_length(), \ 79 klass_name->bytes(), klass_name->utf8_length(), \
79 name->bytes(), name->utf8_length(), \ 80 name->bytes(), name->utf8_length(), \
80 signature->bytes(), signature->utf8_length()); \ 81 signature->bytes(), signature->utf8_length()); \
81 } 82 }
82 83
83 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, \ 84 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
84 comp_name, success) \
85 { \ 85 { \
86 Symbol* klass_name = (method)->klass_name(); \ 86 Symbol* klass_name = (method)->klass_name(); \
87 Symbol* name = (method)->name(); \ 87 Symbol* name = (method)->name(); \
88 Symbol* signature = (method)->signature(); \ 88 Symbol* signature = (method)->signature(); \
89 HS_DTRACE_PROBE9(hotspot, method__compile__end, \ 89 HS_DTRACE_PROBE9(hotspot, method__compile__end, \
93 signature->bytes(), signature->utf8_length(), (success)); \ 93 signature->bytes(), signature->utf8_length(), (success)); \
94 } 94 }
95 95
96 #else /* USDT2 */ 96 #else /* USDT2 */
97 97
98 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method, comp_name) \ 98 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
99 { \ 99 { \
100 Symbol* klass_name = (method)->klass_name(); \ 100 Symbol* klass_name = (method)->klass_name(); \
101 Symbol* name = (method)->name(); \ 101 Symbol* name = (method)->name(); \
102 Symbol* signature = (method)->signature(); \ 102 Symbol* signature = (method)->signature(); \
103 HOTSPOT_METHOD_COMPILE_BEGIN( \ 103 HOTSPOT_METHOD_COMPILE_BEGIN( \
105 (char *) klass_name->bytes(), klass_name->utf8_length(), \ 105 (char *) klass_name->bytes(), klass_name->utf8_length(), \
106 (char *) name->bytes(), name->utf8_length(), \ 106 (char *) name->bytes(), name->utf8_length(), \
107 (char *) signature->bytes(), signature->utf8_length()); \ 107 (char *) signature->bytes(), signature->utf8_length()); \
108 } 108 }
109 109
110 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, \ 110 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
111 comp_name, success) \
112 { \ 111 { \
113 Symbol* klass_name = (method)->klass_name(); \ 112 Symbol* klass_name = (method)->klass_name(); \
114 Symbol* name = (method)->name(); \ 113 Symbol* name = (method)->name(); \
115 Symbol* signature = (method)->signature(); \ 114 Symbol* signature = (method)->signature(); \
116 HOTSPOT_METHOD_COMPILE_END( \ 115 HOTSPOT_METHOD_COMPILE_END( \
121 } 120 }
122 #endif /* USDT2 */ 121 #endif /* USDT2 */
123 122
124 #else // ndef DTRACE_ENABLED 123 #else // ndef DTRACE_ENABLED
125 124
126 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method, comp_name) 125 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name)
127 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, comp_name, success) 126 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success)
128 127
129 #endif // ndef DTRACE_ENABLED 128 #endif // ndef DTRACE_ENABLED
130 129
131 bool CompileBroker::_initialized = false; 130 bool CompileBroker::_initialized = false;
132 volatile bool CompileBroker::_should_block = false; 131 volatile bool CompileBroker::_should_block = false;
182 int CompileBroker::_sum_osr_bytes_compiled = 0; 181 int CompileBroker::_sum_osr_bytes_compiled = 0;
183 int CompileBroker::_sum_standard_bytes_compiled = 0; 182 int CompileBroker::_sum_standard_bytes_compiled = 0;
184 int CompileBroker::_sum_nmethod_size = 0; 183 int CompileBroker::_sum_nmethod_size = 0;
185 int CompileBroker::_sum_nmethod_code_size = 0; 184 int CompileBroker::_sum_nmethod_code_size = 0;
186 185
187 CompileQueue* CompileBroker::_c2_method_queue = NULL; 186 long CompileBroker::_peak_compilation_time = 0;
188 CompileQueue* CompileBroker::_c1_method_queue = NULL; 187
189 CompileTask* CompileBroker::_task_free_list = NULL; 188 CompileQueue* CompileBroker::_c2_method_queue = NULL;
189 CompileQueue* CompileBroker::_c1_method_queue = NULL;
190 CompileTask* CompileBroker::_task_free_list = NULL;
190 191
191 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; 192 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL;
192 193
193 194
194 class CompilationLog : public StringEventLog { 195 class CompilationLog : public StringEventLog {
1246 } 1247 }
1247 } 1248 }
1248 if (method->is_not_compilable(comp_level)) return NULL; 1249 if (method->is_not_compilable(comp_level)) return NULL;
1249 1250
1250 if (UseCodeCacheFlushing) { 1251 if (UseCodeCacheFlushing) {
1251 nmethod* saved = CodeCache::find_and_remove_saved_code(method()); 1252 nmethod* saved = CodeCache::reanimate_saved_code(method());
1252 if (saved != NULL) { 1253 if (saved != NULL) {
1253 method->set_code(method, saved); 1254 method->set_code(method, saved);
1254 return saved; 1255 return saved;
1255 } 1256 }
1256 } 1257 }
1305 // a lock the compiling thread can not acquire. Prefetch it here. 1306 // a lock the compiling thread can not acquire. Prefetch it here.
1306 if (JvmtiExport::should_post_compiled_method_load()) { 1307 if (JvmtiExport::should_post_compiled_method_load()) {
1307 method->jmethod_id(); 1308 method->jmethod_id();
1308 } 1309 }
1309 1310
1310 // If the compiler is shut off due to code cache flushing or otherwise, 1311 // If the compiler is shut off due to code cache getting full
1311 // fail out now so blocking compiles dont hang the java thread 1312 // fail out now so blocking compiles dont hang the java thread
1312 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { 1313 if (!should_compile_new_jobs()) {
1313 CompilationPolicy::policy()->delay_compilation(method()); 1314 CompilationPolicy::policy()->delay_compilation(method());
1314 return NULL; 1315 return NULL;
1315 } 1316 }
1316 1317
1317 // do the compilation 1318 // do the compilation
1598 while (true) { 1599 while (true) {
1599 { 1600 {
1600 // We need this HandleMark to avoid leaking VM handles. 1601 // We need this HandleMark to avoid leaking VM handles.
1601 HandleMark hm(thread); 1602 HandleMark hm(thread);
1602 1603
1603 if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) { 1604 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
1604 // the code cache is really full 1605 // the code cache is really full
1605 handle_full_code_cache(); 1606 handle_full_code_cache();
1606 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { 1607 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) {
1607 // Attempt to start cleaning the code cache while there is still a little headroom 1608 // Attempt to start cleaning the code cache while there is still a little headroom
1608 NMethodSweeper::handle_full_code_cache(false); 1609 NMethodSweeper::handle_full_code_cache(false);
1661 // CompileBroker::init_compiler_thread_log 1662 // CompileBroker::init_compiler_thread_log
1662 // 1663 //
1663 // Set up state required by +LogCompilation. 1664 // Set up state required by +LogCompilation.
1664 void CompileBroker::init_compiler_thread_log() { 1665 void CompileBroker::init_compiler_thread_log() {
1665 CompilerThread* thread = CompilerThread::current(); 1666 CompilerThread* thread = CompilerThread::current();
1666 char fileBuf[4*K]; 1667 char file_name[4*K];
1667 FILE* fp = NULL; 1668 FILE* fp = NULL;
1668 char* file = NULL;
1669 intx thread_id = os::current_thread_id(); 1669 intx thread_id = os::current_thread_id();
1670 for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) { 1670 for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) {
1671 const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL); 1671 const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL);
1672 if (dir == NULL) { 1672 if (dir == NULL) {
1673 jio_snprintf(fileBuf, sizeof(fileBuf), "hs_c" UINTX_FORMAT "_pid%u.log", 1673 jio_snprintf(file_name, sizeof(file_name), "hs_c" UINTX_FORMAT "_pid%u.log",
1674 thread_id, os::current_process_id()); 1674 thread_id, os::current_process_id());
1675 } else { 1675 } else {
1676 jio_snprintf(fileBuf, sizeof(fileBuf), 1676 jio_snprintf(file_name, sizeof(file_name),
1677 "%s%shs_c" UINTX_FORMAT "_pid%u.log", dir, 1677 "%s%shs_c" UINTX_FORMAT "_pid%u.log", dir,
1678 os::file_separator(), thread_id, os::current_process_id()); 1678 os::file_separator(), thread_id, os::current_process_id());
1679 } 1679 }
1680 fp = fopen(fileBuf, "at"); 1680
1681 fp = fopen(file_name, "at");
1681 if (fp != NULL) { 1682 if (fp != NULL) {
1682 file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1, mtCompiler); 1683 if (LogCompilation && Verbose) {
1683 strcpy(file, fileBuf); 1684 tty->print_cr("Opening compilation log %s", file_name);
1684 break; 1685 }
1686 CompileLog* log = new(ResourceObj::C_HEAP, mtCompiler) CompileLog(file_name, fp, thread_id);
1687 thread->init_log(log);
1688
1689 if (xtty != NULL) {
1690 ttyLocker ttyl;
1691 // Record any per thread log files
1692 xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file_name);
1693 }
1694 return;
1685 } 1695 }
1686 } 1696 }
1687 if (fp == NULL) { 1697 warning("Cannot open log file: %s", file_name);
1688 warning("Cannot open log file: %s", fileBuf);
1689 } else {
1690 if (LogCompilation && Verbose)
1691 tty->print_cr("Opening compilation log %s", file);
1692 CompileLog* log = new(ResourceObj::C_HEAP, mtCompiler) CompileLog(file, fp, thread_id);
1693 thread->init_log(log);
1694
1695 if (xtty != NULL) {
1696 ttyLocker ttyl;
1697
1698 // Record any per thread log files
1699 xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file);
1700 }
1701 }
1702 } 1698 }
1703 1699
1704 // ------------------------------------------------------------------ 1700 // ------------------------------------------------------------------
1705 // CompileBroker::set_should_block 1701 // CompileBroker::set_should_block
1706 // 1702 //
1783 assert(!method->is_native(), "no longer compile natives"); 1779 assert(!method->is_native(), "no longer compile natives");
1784 1780
1785 // Save information about this method in case of failure. 1781 // Save information about this method in case of failure.
1786 set_last_compile(thread, method, is_osr, task_level); 1782 set_last_compile(thread, method, is_osr, task_level);
1787 1783
1788 DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task_level), method, 1784 DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
1789 compiler_name(task_level));
1790 } 1785 }
1791 1786
1792 // Allocate a new set of JNI handles. 1787 // Allocate a new set of JNI handles.
1793 push_jni_handle_block(); 1788 push_jni_handle_block();
1794 Method* target_handle = task->method(); 1789 Method* target_handle = task->method();
1820 ci_env.cache_dtrace_flags(); 1815 ci_env.cache_dtrace_flags();
1821 1816
1822 ciMethod* target = ci_env.get_method_from_handle(target_handle); 1817 ciMethod* target = ci_env.get_method_from_handle(target_handle);
1823 1818
1824 TraceTime t1("compilation", &time); 1819 TraceTime t1("compilation", &time);
1820 EventCompilation event;
1825 1821
1826 AbstractCompiler *comp = compiler(task_level); 1822 AbstractCompiler *comp = compiler(task_level);
1827 if (comp == NULL) { 1823 if (comp == NULL) {
1828 ci_env.record_method_not_compilable("no compiler", !TieredCompilation); 1824 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1829 } else { 1825 } else {
1859 if (code != NULL) { 1855 if (code != NULL) {
1860 _compilation_log->log_nmethod(thread, code); 1856 _compilation_log->log_nmethod(thread, code);
1861 } 1857 }
1862 } 1858 }
1863 } 1859 }
1860 // simulate crash during compilation
1861 assert(task->compile_id() != CICrashAt, "just as planned");
1862 if (event.should_commit()) {
1863 event.set_method(target->get_Method());
1864 event.set_compileID(compile_id);
1865 event.set_compileLevel(task->comp_level());
1866 event.set_succeded(task->is_success());
1867 event.set_isOsr(is_osr);
1868 event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1869 event.set_inlinedBytes(task->num_inlined_bytecodes());
1870 event.commit();
1871 }
1864 } 1872 }
1865 pop_jni_handle_block(); 1873 pop_jni_handle_block();
1866 1874
1867 methodHandle method(thread, task->method()); 1875 methodHandle method(thread, task->method());
1868 1876
1869 DTRACE_METHOD_COMPILE_END_PROBE(compiler(task_level), method, 1877 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
1870 compiler_name(task_level), task->is_success());
1871 1878
1872 collect_statistics(thread, time, task); 1879 collect_statistics(thread, time, task);
1873 1880
1874 if (PrintCompilation && PrintCompilation2) { 1881 if (PrintCompilation && PrintCompilation2) {
1875 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp 1882 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp
1876 tty->print("%4d ", compile_id); // print compilation number 1883 tty->print("%4d ", compile_id); // print compilation number
1877 tty->print("%s ", (is_osr ? "%" : " ")); 1884 tty->print("%s ", (is_osr ? "%" : " "));
1878 int code_size = (task->code() == NULL) ? 0 : task->code()->total_size(); 1885 if (task->code() != NULL) {
1879 tty->print_cr("size: %d time: %d inlined: %d bytes", code_size, (int)time.milliseconds(), task->num_inlined_bytecodes()); 1886 tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
1887 }
1888 tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
1880 } 1889 }
1881 1890
1882 if (PrintCodeCacheOnCompilation) 1891 if (PrintCodeCacheOnCompilation)
1883 codecache_print(/* detailed= */ false); 1892 codecache_print(/* detailed= */ false);
1884 1893
1938 xtty->stamp(); 1947 xtty->stamp();
1939 xtty->end_elem(); 1948 xtty->end_elem();
1940 } 1949 }
1941 warning("CodeCache is full. Compiler has been disabled."); 1950 warning("CodeCache is full. Compiler has been disabled.");
1942 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize="); 1951 warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
1952
1953 CodeCache::report_codemem_full();
1954
1955
1943 #ifndef PRODUCT 1956 #ifndef PRODUCT
1944 if (CompileTheWorld || ExitOnFullCodeCache) { 1957 if (CompileTheWorld || ExitOnFullCodeCache) {
1945 codecache_print(/* detailed= */ true); 1958 codecache_print(/* detailed= */ true);
1946 before_exit(JavaThread::current()); 1959 before_exit(JavaThread::current());
1947 exit_globals(); // will delete tty 1960 exit_globals(); // will delete tty
2095 2108
2096 // update compilation ticks - used by the implementation of 2109 // update compilation ticks - used by the implementation of
2097 // java.lang.management.CompilationMBean 2110 // java.lang.management.CompilationMBean
2098 _perf_total_compilation->inc(time.ticks()); 2111 _perf_total_compilation->inc(time.ticks());
2099 2112
2113 _t_total_compilation.add(time);
2114 _peak_compilation_time = time.milliseconds() > _peak_compilation_time ? time.milliseconds() : _peak_compilation_time;
2115
2100 if (CITime) { 2116 if (CITime) {
2101 _t_total_compilation.add(time);
2102 if (is_osr) { 2117 if (is_osr) {
2103 _t_osr_compilation.add(time); 2118 _t_osr_compilation.add(time);
2104 _sum_osr_bytes_compiled += method->code_size() + task->num_inlined_bytecodes(); 2119 _sum_osr_bytes_compiled += method->code_size() + task->num_inlined_bytecodes();
2105 #ifdef GRAAL 2120 #ifdef GRAAL
2106 compiler(task->comp_level())->stats()->_t_osr_compilation.add(time); 2121 compiler(task->comp_level())->stats()->_t_osr_compilation.add(time);
2219 tty->cr(); 2234 tty->cr();
2220 tty->print_cr(" nmethod code size : %6d bytes", CompileBroker::_sum_nmethod_code_size); 2235 tty->print_cr(" nmethod code size : %6d bytes", CompileBroker::_sum_nmethod_code_size);
2221 tty->print_cr(" nmethod total size : %6d bytes", CompileBroker::_sum_nmethod_size); 2236 tty->print_cr(" nmethod total size : %6d bytes", CompileBroker::_sum_nmethod_size);
2222 } 2237 }
2223 2238
2224
2225 // Debugging output for failure 2239 // Debugging output for failure
2226 void CompileBroker::print_last_compile() { 2240 void CompileBroker::print_last_compile() {
2227 if ( _last_compile_level != CompLevel_none && 2241 if ( _last_compile_level != CompLevel_none &&
2228 compiler(_last_compile_level) != NULL && 2242 compiler(_last_compile_level) != NULL &&
2229 _last_method_compiled != NULL && 2243 _last_method_compiled != NULL &&