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