33 #include "compiler/compilerOracle.hpp"
34 #include "compiler/directivesParser.hpp"
35 #include "interpreter/linkResolver.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "oops/method.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "prims/nativeLookup.hpp"
42 #include "prims/whitebox.hpp"
43 #include "runtime/arguments.hpp"
44 #include "runtime/atomic.hpp"
45 #include "runtime/compilationPolicy.hpp"
46 #include "runtime/init.hpp"
47 #include "runtime/interfaceSupport.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/os.hpp"
50 #include "runtime/sharedRuntime.hpp"
51 #include "runtime/sweeper.hpp"
52 #include "runtime/timerTrace.hpp"
53 #include "trace/tracing.hpp"
54 #include "utilities/dtrace.hpp"
55 #include "utilities/events.hpp"
56 #ifdef COMPILER1
57 #include "c1/c1_Compiler.hpp"
58 #endif
59 #if INCLUDE_JVMCI
60 #include "jvmci/jvmciCompiler.hpp"
61 #include "jvmci/jvmciRuntime.hpp"
62 #include "jvmci/jvmciJavaClasses.hpp"
63 #include "runtime/vframe.hpp"
64 #endif
65 #ifdef COMPILER2
66 #include "opto/c2compiler.hpp"
67 #endif
68 #ifdef SHARK
69 #include "shark/sharkCompiler.hpp"
70 #endif
71
72 #ifdef DTRACE_ENABLED
73
74 // Only bother with this argument setup if dtrace is available
75
76 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
77 { \
78 Symbol* klass_name = (method)->klass_name(); \
79 Symbol* name = (method)->name(); \
80 Symbol* signature = (method)->signature(); \
81 HOTSPOT_METHOD_COMPILE_BEGIN( \
82 (char *) comp_name, strlen(comp_name), \
83 (char *) klass_name->bytes(), klass_name->utf8_length(), \
84 (char *) name->bytes(), name->utf8_length(), \
85 (char *) signature->bytes(), signature->utf8_length()); \
86 }
87
88 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
89 { \
90 Symbol* klass_name = (method)->klass_name(); \
1734 // Dump code cache into a buffer
1735 {
1736 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1737 CodeCache::print_summary(&s, detailed);
1738 }
1739
1740 char* remaining_log = s.as_string();
1741 while (*remaining_log != '\0') {
1742 char* eol = strchr(remaining_log, '\n');
1743 if (eol == NULL) {
1744 out->print_cr("%s", remaining_log);
1745 remaining_log = remaining_log + strlen(remaining_log);
1746 } else {
1747 *eol = '\0';
1748 out->print_cr("%s", remaining_log);
1749 remaining_log = eol + 1;
1750 }
1751 }
1752 }
1753
1754 void CompileBroker::post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env) {
1755
1756 if (success) {
1757 task->mark_success();
1758 if (ci_env != NULL) {
1759 task->set_num_inlined_bytecodes(ci_env->num_inlined_bytecodes());
1760 }
1761 if (_compilation_log != NULL) {
1762 nmethod* code = task->code();
1763 if (code != NULL) {
1764 _compilation_log->log_nmethod(thread, code);
1765 }
1766 }
1767 }
1768
1769 // simulate crash during compilation
1770 assert(task->compile_id() != CICrashAt, "just as planned");
1771 if (event.should_commit()) {
1772 event.set_method(task->method());
1773 event.set_compileId(task->compile_id());
1774 event.set_compileLevel(task->comp_level());
1775 event.set_succeded(task->is_success());
1776 event.set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci);
1777 event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1778 event.set_inlinedBytes(task->num_inlined_bytecodes());
1779 event.commit();
1780 }
1781 }
1782
1783 int DirectivesStack::_depth = 0;
1784 CompilerDirectives* DirectivesStack::_top = NULL;
1785 CompilerDirectives* DirectivesStack::_bottom = NULL;
1786
1787 // ------------------------------------------------------------------
1788 // CompileBroker::invoke_compiler_on_method
1789 //
1790 // Compile a method.
1791 //
1792 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1793 task->print_ul();
1794 if (PrintCompilation) {
1795 ResourceMark rm;
1796 task->print_tty();
1797 }
1798 elapsedTimer time;
1799
1800 CompilerThread* thread = CompilerThread::current();
1801 ResourceMark rm(thread);
1837 }
1838
1839 // Allocate a new set of JNI handles.
1840 push_jni_handle_block();
1841 Method* target_handle = task->method();
1842 int compilable = ciEnv::MethodCompilable;
1843 const char* failure_reason = NULL;
1844 const char* retry_message = NULL;
1845
1846 int system_dictionary_modification_counter;
1847 {
1848 MutexLocker locker(Compile_lock, thread);
1849 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1850 }
1851
1852 #if INCLUDE_JVMCI
1853 if (UseJVMCICompiler && comp != NULL && comp->is_jvmci()) {
1854 JVMCICompiler* jvmci = (JVMCICompiler*) comp;
1855
1856 TraceTime t1("compilation", &time);
1857 EventCompilation event;
1858
1859 JVMCIEnv env(task, system_dictionary_modification_counter);
1860 methodHandle method(thread, target_handle);
1861 jvmci->compile_method(method, osr_bci, &env);
1862
1863 post_compile(thread, task, event, task->code() != NULL, NULL);
1864
1865 failure_reason = env.failure_reason();
1866 if (!env.retryable()) {
1867 retry_message = "not retryable";
1868 compilable = ciEnv::MethodCompilable_not_at_tier;
1869 }
1870
1871 } else
1872 #endif // INCLUDE_JVMCI
1873 {
1874 NoHandleMark nhm;
1875 ThreadToNativeFromVM ttn(thread);
1876
1877 ciEnv ci_env(task, system_dictionary_modification_counter);
1878 if (should_break) {
1879 ci_env.set_break_at_compile(true);
1880 }
1881 if (should_log) {
1882 ci_env.set_log(thread->log());
1883 }
1884 assert(thread->env() == &ci_env, "set by ci_env");
1885 // The thread-env() field is cleared in ~CompileTaskWrapper.
1886
1887 // Cache Jvmti state
1888 ci_env.cache_jvmti_state();
1889
1890 // Cache DTrace flags
1891 ci_env.cache_dtrace_flags();
1892
1893 ciMethod* target = ci_env.get_method_from_handle(target_handle);
1894
1895 TraceTime t1("compilation", &time);
1896 EventCompilation event;
1897
1898 if (comp == NULL) {
1899 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1900 } else {
1901 if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1902 MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1903 while (WhiteBox::compilation_locked) {
1904 locker.wait(Mutex::_no_safepoint_check_flag);
1905 }
1906 }
1907 comp->compile_method(&ci_env, target, osr_bci, directive);
1908 }
1909
1910 if (!ci_env.failing() && task->code() == NULL) {
1911 //assert(false, "compiler should always document failure");
1912 // The compiler elected, without comment, not to register a result.
1913 // Do not attempt further compilations of this method.
1914 ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1915 }
1916
1917 // Copy this bit to the enclosing block:
1918 compilable = ci_env.compilable();
1919
1920 if (ci_env.failing()) {
1921 failure_reason = ci_env.failure_reason();
1922 retry_message = ci_env.retry_message();
1923 ci_env.report_failure(failure_reason);
1924 }
1925
1926 post_compile(thread, task, event, !ci_env.failing(), &ci_env);
1927 }
1928 // Remove the JNI handle block after the ciEnv destructor has run in
1929 // the previous block.
1930 pop_jni_handle_block();
1931
1932 if (failure_reason != NULL) {
1933 task->set_failure_reason(failure_reason);
1934 if (_compilation_log != NULL) {
1935 _compilation_log->log_failure(thread, task, failure_reason, retry_message);
1936 }
1937 if (PrintCompilation) {
1938 FormatBufferResource msg = retry_message != NULL ?
1939 FormatBufferResource("COMPILE SKIPPED: %s (%s)", failure_reason, retry_message) :
1940 FormatBufferResource("COMPILE SKIPPED: %s", failure_reason);
1941 task->print(tty, msg);
1942 }
1943 }
1944
1945 methodHandle method(thread, task->method());
1946
|
33 #include "compiler/compilerOracle.hpp"
34 #include "compiler/directivesParser.hpp"
35 #include "interpreter/linkResolver.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "oops/method.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "prims/nativeLookup.hpp"
42 #include "prims/whitebox.hpp"
43 #include "runtime/arguments.hpp"
44 #include "runtime/atomic.hpp"
45 #include "runtime/compilationPolicy.hpp"
46 #include "runtime/init.hpp"
47 #include "runtime/interfaceSupport.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/os.hpp"
50 #include "runtime/sharedRuntime.hpp"
51 #include "runtime/sweeper.hpp"
52 #include "runtime/timerTrace.hpp"
53 #include "utilities/dtrace.hpp"
54 #include "utilities/events.hpp"
55 #include "utilities/macros.hpp"
56 #ifdef COMPILER1
57 #include "c1/c1_Compiler.hpp"
58 #endif
59 #if INCLUDE_JVMCI
60 #include "jvmci/jvmciCompiler.hpp"
61 #include "jvmci/jvmciRuntime.hpp"
62 #include "jvmci/jvmciJavaClasses.hpp"
63 #include "runtime/vframe.hpp"
64 #endif
65 #ifdef COMPILER2
66 #include "opto/c2compiler.hpp"
67 #endif
68 #ifdef SHARK
69 #include "shark/sharkCompiler.hpp"
70 #endif
71 #if INCLUDE_TRACE
72 #include "trace/tracing.hpp"
73 #endif
74
75 #ifdef DTRACE_ENABLED
76
77 // Only bother with this argument setup if dtrace is available
78
79 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
80 { \
81 Symbol* klass_name = (method)->klass_name(); \
82 Symbol* name = (method)->name(); \
83 Symbol* signature = (method)->signature(); \
84 HOTSPOT_METHOD_COMPILE_BEGIN( \
85 (char *) comp_name, strlen(comp_name), \
86 (char *) klass_name->bytes(), klass_name->utf8_length(), \
87 (char *) name->bytes(), name->utf8_length(), \
88 (char *) signature->bytes(), signature->utf8_length()); \
89 }
90
91 #define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
92 { \
93 Symbol* klass_name = (method)->klass_name(); \
1737 // Dump code cache into a buffer
1738 {
1739 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1740 CodeCache::print_summary(&s, detailed);
1741 }
1742
1743 char* remaining_log = s.as_string();
1744 while (*remaining_log != '\0') {
1745 char* eol = strchr(remaining_log, '\n');
1746 if (eol == NULL) {
1747 out->print_cr("%s", remaining_log);
1748 remaining_log = remaining_log + strlen(remaining_log);
1749 } else {
1750 *eol = '\0';
1751 out->print_cr("%s", remaining_log);
1752 remaining_log = eol + 1;
1753 }
1754 }
1755 }
1756
1757 void CompileBroker::post_compile(CompilerThread* thread,
1758 CompileTask* task,
1759 bool success,
1760 ciEnv* ci_env) {
1761 if (success) {
1762 task->mark_success();
1763 if (ci_env != NULL) {
1764 task->set_num_inlined_bytecodes(ci_env->num_inlined_bytecodes());
1765 }
1766 if (_compilation_log != NULL) {
1767 nmethod* code = task->code();
1768 if (code != NULL) {
1769 _compilation_log->log_nmethod(thread, code);
1770 }
1771 }
1772 }
1773
1774 // simulate crash during compilation
1775 assert(task->compile_id() != CICrashAt, "just as planned");
1776 }
1777
1778 #if INCLUDE_TRACE
1779 static void post_compilation_event(EventCompilation* event,
1780 CompilerThread* thread,
1781 CompileTask* task,
1782 CompilationLog* log,
1783 bool success,
1784 ciEnv* ci_env) {
1785 assert(event != NULL, "invariant");
1786 if (event->should_commit()) {
1787 event->set_method(task->method());
1788 event->set_compileId(task->compile_id());
1789 event->set_compileLevel(task->comp_level());
1790 event->set_succeded(task->is_success());
1791 event->set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci);
1792 event->set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1793 event->set_inlinedBytes(task->num_inlined_bytecodes());
1794 event->commit();
1795 }
1796 }
1797 #endif // INCLUDE_TRACE
1798
1799 int DirectivesStack::_depth = 0;
1800 CompilerDirectives* DirectivesStack::_top = NULL;
1801 CompilerDirectives* DirectivesStack::_bottom = NULL;
1802
1803 // ------------------------------------------------------------------
1804 // CompileBroker::invoke_compiler_on_method
1805 //
1806 // Compile a method.
1807 //
1808 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1809 task->print_ul();
1810 if (PrintCompilation) {
1811 ResourceMark rm;
1812 task->print_tty();
1813 }
1814 elapsedTimer time;
1815
1816 CompilerThread* thread = CompilerThread::current();
1817 ResourceMark rm(thread);
1853 }
1854
1855 // Allocate a new set of JNI handles.
1856 push_jni_handle_block();
1857 Method* target_handle = task->method();
1858 int compilable = ciEnv::MethodCompilable;
1859 const char* failure_reason = NULL;
1860 const char* retry_message = NULL;
1861
1862 int system_dictionary_modification_counter;
1863 {
1864 MutexLocker locker(Compile_lock, thread);
1865 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1866 }
1867
1868 #if INCLUDE_JVMCI
1869 if (UseJVMCICompiler && comp != NULL && comp->is_jvmci()) {
1870 JVMCICompiler* jvmci = (JVMCICompiler*) comp;
1871
1872 TraceTime t1("compilation", &time);
1873 TRACE_ONLY(EventCompilation event;)
1874
1875 JVMCIEnv env(task, system_dictionary_modification_counter);
1876 methodHandle method(thread, target_handle);
1877 jvmci->compile_method(method, osr_bci, &env);
1878 post_compile(thread, task, task->code() != NULL, NULL);
1879 TRACE_ONLY(post_compilation_event(&event,
1880 thread,
1881 task,
1882 _compilation_log,
1883 task->code() != NULL,
1884 NULL);)
1885
1886 failure_reason = env.failure_reason();
1887 if (!env.retryable()) {
1888 retry_message = "not retryable";
1889 compilable = ciEnv::MethodCompilable_not_at_tier;
1890 }
1891
1892 } else
1893 #endif // INCLUDE_JVMCI
1894 {
1895 NoHandleMark nhm;
1896 ThreadToNativeFromVM ttn(thread);
1897
1898 ciEnv ci_env(task, system_dictionary_modification_counter);
1899 if (should_break) {
1900 ci_env.set_break_at_compile(true);
1901 }
1902 if (should_log) {
1903 ci_env.set_log(thread->log());
1904 }
1905 assert(thread->env() == &ci_env, "set by ci_env");
1906 // The thread-env() field is cleared in ~CompileTaskWrapper.
1907
1908 // Cache Jvmti state
1909 ci_env.cache_jvmti_state();
1910
1911 // Cache DTrace flags
1912 ci_env.cache_dtrace_flags();
1913
1914 ciMethod* target = ci_env.get_method_from_handle(target_handle);
1915
1916 TraceTime t1("compilation", &time);
1917 TRACE_ONLY(EventCompilation event;)
1918
1919 if (comp == NULL) {
1920 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1921 } else {
1922 if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1923 MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1924 while (WhiteBox::compilation_locked) {
1925 locker.wait(Mutex::_no_safepoint_check_flag);
1926 }
1927 }
1928 comp->compile_method(&ci_env, target, osr_bci, directive);
1929 }
1930
1931 if (!ci_env.failing() && task->code() == NULL) {
1932 //assert(false, "compiler should always document failure");
1933 // The compiler elected, without comment, not to register a result.
1934 // Do not attempt further compilations of this method.
1935 ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1936 }
1937
1938 // Copy this bit to the enclosing block:
1939 compilable = ci_env.compilable();
1940
1941 if (ci_env.failing()) {
1942 failure_reason = ci_env.failure_reason();
1943 retry_message = ci_env.retry_message();
1944 ci_env.report_failure(failure_reason);
1945 }
1946
1947 post_compile(thread, task, !ci_env.failing(), &ci_env);
1948 TRACE_ONLY(post_compilation_event(&event,
1949 thread,
1950 task,
1951 _compilation_log,
1952 !ci_env.failing(),
1953 &ci_env);)
1954 }
1955 // Remove the JNI handle block after the ciEnv destructor has run in
1956 // the previous block.
1957 pop_jni_handle_block();
1958
1959 if (failure_reason != NULL) {
1960 task->set_failure_reason(failure_reason);
1961 if (_compilation_log != NULL) {
1962 _compilation_log->log_failure(thread, task, failure_reason, retry_message);
1963 }
1964 if (PrintCompilation) {
1965 FormatBufferResource msg = retry_message != NULL ?
1966 FormatBufferResource("COMPILE SKIPPED: %s (%s)", failure_reason, retry_message) :
1967 FormatBufferResource("COMPILE SKIPPED: %s", failure_reason);
1968 task->print(tty, msg);
1969 }
1970 }
1971
1972 methodHandle method(thread, task->method());
1973
|