# HG changeset patch # User Christian Haeubl # Date 1352976050 -3600 # Node ID 8c5333c80cfd55589935ba68b1cb132143c9b1a6 # Parent 5bbe9618118e78d23dadd19d91a36514fe361ba3 increased CompileThreshold to increase reliability of profiling information increased InitialCodeCacheSize to fit the bootstrapping added flag -XX:GraalClassPath to allow providing a .jar or .zip file that contains all Graal classes added support for the flag -XX:TraceCompilationPolicy to the Graal-specific compilation policy diff -r 5bbe9618118e -r 8c5333c80cfd src/cpu/x86/vm/c1_globals_x86.hpp --- a/src/cpu/x86/vm/c1_globals_x86.hpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/cpu/x86/vm/c1_globals_x86.hpp Thu Nov 15 11:40:50 2012 +0100 @@ -52,8 +52,8 @@ #ifdef GRAAL define_pd_global(bool, ProfileTraps, true ); define_pd_global(bool, UseOnStackReplacement, true); -define_pd_global(intx, CompileThreshold, 2500 ); -define_pd_global(intx, InitialCodeCacheSize, 4*M ); +define_pd_global(intx, CompileThreshold, 10000 ); +define_pd_global(intx, InitialCodeCacheSize, 16*M ); define_pd_global(intx, ReservedCodeCacheSize, 64*M ); define_pd_global(bool, ProfileInterpreter, true ); define_pd_global(intx, CodeCacheExpansionSize, 64*K ); diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/c1/c1_globals.hpp --- a/src/share/vm/c1/c1_globals.hpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/c1/c1_globals.hpp Thu Nov 15 11:40:50 2012 +0100 @@ -60,6 +60,8 @@ "Enable JVMTI for the compiler thread") \ product(bool, BootstrapGraal, true, \ "Bootstrap graal before running Java main method") \ + product(ccstr, GraalClassPath, NULL, \ + "Use the defined graal class path instead of searching for the classes") \ product(intx, TraceGraal, 0, \ "Trace level for graal") \ product(bool, TraceSignals, false, \ diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/code/codeBlob.cpp --- a/src/share/vm/code/codeBlob.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/code/codeBlob.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -39,6 +39,7 @@ #include "runtime/sharedRuntime.hpp" #include "runtime/vframe.hpp" #include "services/memoryService.hpp" +#include "utilities/machineCodePrinter.hpp" #ifdef TARGET_ARCH_x86 # include "nativeInst_x86.hpp" #endif @@ -340,6 +341,10 @@ trace_new_stub(stub, "RuntimeStub - ", stub_name); + if (PrintMachineCodeToFile) { + MachineCodePrinter::print(stub); + } + return stub; } diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/code/icBuffer.cpp --- a/src/share/vm/code/icBuffer.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/code/icBuffer.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -106,8 +106,8 @@ void ICStub::verify() { } -void ICStub::print() { - tty->print_cr("ICStub: site: " INTPTR_FORMAT, _ic_site); +void ICStub::print_on(outputStream* st) { + st->print_cr("ICStub: site: " INTPTR_FORMAT, _ic_site); } #endif diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/code/icBuffer.hpp --- a/src/share/vm/code/icBuffer.hpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/code/icBuffer.hpp Thu Nov 15 11:40:50 2012 +0100 @@ -73,8 +73,8 @@ oop cached_oop() const; // cached_oop for stub // Debugging - void verify() PRODUCT_RETURN; - void print() PRODUCT_RETURN; + void verify() PRODUCT_RETURN; + void print_on(outputStream* st) PRODUCT_RETURN; // Creation friend ICStub* ICStub_from_destination_address(address destination_address); diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/code/nmethod.cpp --- a/src/share/vm/code/nmethod.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/code/nmethod.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -42,6 +42,7 @@ #include "utilities/dtrace.hpp" #include "utilities/events.hpp" #include "utilities/xmlstream.hpp" +#include "utilities/machineCodePrinter.hpp" #ifdef SHARK #include "shark/sharkCompiler.hpp" #endif @@ -514,6 +515,10 @@ if (nm != NULL) nmethod_stats.note_native_nmethod(nm); if (PrintAssembly && nm != NULL) Disassembler::decode(nm); + + if (PrintMachineCodeToFile) { + MachineCodePrinter::print(nm); + } } // verify nmethod debug_only(if (nm) nm->verify();) // might block @@ -614,6 +619,10 @@ if (nm != NULL) nmethod_stats.note_nmethod(nm); if (PrintAssembly && nm != NULL) Disassembler::decode(nm); + + if (PrintMachineCodeToFile) { + MachineCodePrinter::print(nm); + } } // verify nmethod diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/code/stubs.cpp --- a/src/share/vm/code/stubs.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/code/stubs.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -251,10 +251,9 @@ guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same"); } - -void StubQueue::print() { +void StubQueue::print_on(outputStream* st) { MutexLockerEx lock(_mutex); for (Stub* s = first(); s != NULL; s = next(s)) { - stub_print(s); + stub_print(s, st); } } diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/code/stubs.hpp --- a/src/share/vm/code/stubs.hpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/code/stubs.hpp Thu Nov 15 11:40:50 2012 +0100 @@ -117,7 +117,7 @@ // Debugging virtual void verify(Stub* self) = 0; // verifies the stub - virtual void print(Stub* self) = 0; // prints information about the stub + virtual void print_on(Stub* self, outputStream* st) = 0; // prints information about the stub }; @@ -145,7 +145,7 @@ \ /* Debugging */ \ virtual void verify(Stub* self) { cast(self)->verify(); } \ - virtual void print(Stub* self) { cast(self)->print(); } \ + virtual void print_on(Stub* self, outputStream* st) { cast(self)->print_on(st); } \ }; @@ -177,7 +177,7 @@ bool stub_contains(Stub* s, address pc) const { return _stub_interface->code_begin(s) <= pc && pc < _stub_interface->code_end(s); } int stub_code_size_to_size(int code_size) const { return _stub_interface->code_size_to_size(code_size); } void stub_verify(Stub* s) { _stub_interface->verify(s); } - void stub_print(Stub* s) { _stub_interface->print(s); } + void stub_print(Stub* s, outputStream* st) { _stub_interface->print_on(s, st); } static void register_queue(StubQueue*); @@ -221,7 +221,8 @@ // Debugging/printing void verify(); // verifies the stub queue - void print(); // prints information about the stub queue + void print() { print_on(tty); } + void print_on(outputStream* st); }; #endif // SHARE_VM_CODE_STUBS_HPP diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/compiler/disassembler.cpp --- a/src/share/vm/compiler/disassembler.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/compiler/disassembler.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -463,7 +463,8 @@ void Disassembler::decode(CodeBlob* cb, outputStream* st) { if (!load_library()) return; decode_env env(cb, st); - env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, cb); + env.output()->print_cr("----------------------------------------------------------------------"); + env.output()->print_cr("%s at [" PTR_FORMAT ", " PTR_FORMAT "] %d bytes", cb->name(), cb->code_begin(), cb->code_end(), ((jlong)(cb->code_end() - cb->code_begin())) * sizeof(unsigned char*)); env.decode_instructions(cb->code_begin(), cb->code_end()); } @@ -477,8 +478,7 @@ void Disassembler::decode(nmethod* nm, outputStream* st) { if (!load_library()) return; decode_env env(nm, st); - env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", nm); - env.output()->print_cr("Code:"); + env.output()->print_cr("----------------------------------------------------------------------"); #ifdef SHARK SharkEntry* entry = (SharkEntry *) nm->code_begin(); @@ -489,6 +489,11 @@ unsigned char* end = nm->code_end(); #endif // SHARK + nm->method()->method_holder()->klass_part()->name()->print_symbol_on(env.output()); + env.output()->print("."); + nm->method()->name()->print_symbol_on(env.output()); + env.output()->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT "] %d bytes", p, end, ((jlong)(end - p)) * sizeof(unsigned char*)); + // If there has been profiling, print the buckets. if (FlatProfiler::bucket_start_for(p) != NULL) { unsigned char* p1 = p; diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/compiler/oopMap.cpp --- a/src/share/vm/compiler/oopMap.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/compiler/oopMap.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -545,7 +545,7 @@ st->print("Value" ); break; case OopMapValue::narrowoop_value: - tty->print("NarrowOop" ); + st->print("NarrowOop" ); break; case OopMapValue::callee_saved_value: st->print("Callers_" ); diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/interpreter/interpreter.cpp --- a/src/share/vm/interpreter/interpreter.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/interpreter/interpreter.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -60,8 +60,7 @@ void InterpreterCodelet::print_on(outputStream* st) const { - if (PrintInterpreter) { - st->cr(); + if (PrintInterpreter || PrintMachineCodeToFile) { st->print_cr("----------------------------------------------------------------------"); } @@ -70,8 +69,7 @@ st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes", code_begin(), code_end(), code_size()); - if (PrintInterpreter) { - st->cr(); + if (PrintInterpreter || PrintMachineCodeToFile) { Disassembler::decode(code_begin(), code_end(), st); } } diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/interpreter/templateInterpreter.cpp --- a/src/share/vm/interpreter/templateInterpreter.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/interpreter/templateInterpreter.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -27,6 +27,7 @@ #include "interpreter/interpreterGenerator.hpp" #include "interpreter/interpreterRuntime.hpp" #include "interpreter/templateTable.hpp" +#include "utilities/machineCodePrinter.hpp" #ifndef CC_INTERP @@ -51,6 +52,9 @@ "Interpreter"); InterpreterGenerator g(_code); if (PrintInterpreter) print(); + if (PrintMachineCodeToFile) { + MachineCodePrinter::print(_code); + } } // initialize dispatch table diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/runtime/arguments.cpp --- a/src/share/vm/runtime/arguments.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/runtime/arguments.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -2057,19 +2057,24 @@ // Parse JavaVMInitArgs structure #ifdef GRAAL +static void prepend_to_graal_classpath(SysClassPath &cp, const char* path) { + cp.add_prefix(path); +} + static void prepend_to_graal_classpath(SysClassPath &cp, const char* graal_dir, const char* project) { const int BUFFER_SIZE = 1024; char path[BUFFER_SIZE]; const char fileSep = *os::file_separator(); sprintf(path, "%s%c%s%cbin", graal_dir, fileSep, project, fileSep); + DIR* dir = os::opendir(path); if (dir == NULL) { jio_fprintf(defaultStream::output_stream(), "Error while starting Graal VM: The Graal class directory %s could not be opened.\n", path); vm_exit(1); } os::closedir(dir); - cp.add_prefix(path); + prepend_to_graal_classpath(cp, path); } // Walk up the directory hierarchy starting from JAVA_HOME looking @@ -2134,59 +2139,66 @@ if (PrintVMOptions) { tty->print_cr("Running Graal VM... "); } - const int BUFFER_SIZE = 1024; - char graal_dir[BUFFER_SIZE]; - if (!os::getenv("GRAAL", graal_dir, sizeof(graal_dir))) { - if (find_graal_dir(graal_dir) == false) { - jio_fprintf(defaultStream::output_stream(), "Error while starting Graal VM: The GRAAL environment variable needs to point to the directory containing the Graal projects.\n"); - vm_exit(0); + + SysClassPath scp_compiler(""); + + if (GraalClassPath != NULL) { + prepend_to_graal_classpath(scp_compiler, GraalClassPath); + } else { + const int BUFFER_SIZE = 1024; + char graal_dir[BUFFER_SIZE]; + if (!os::getenv("GRAAL", graal_dir, sizeof(graal_dir))) { + if (find_graal_dir(graal_dir) == false) { + jio_fprintf(defaultStream::output_stream(), "Error while starting Graal VM: The GRAAL environment variable needs to point to the directory containing the Graal projects.\n"); + vm_exit(0); + } + } + if (PrintVMOptions) tty->print_cr("GRAAL=%s", graal_dir); + + // this declaration is checked for correctness by 'mx build' - only + // modify its entries, not its name or shape + const char* graal_projects[] = { + #ifdef AMD64 + "com.oracle.graal.amd64", + "com.oracle.graal.asm.amd64", + "com.oracle.graal.lir.amd64", + "com.oracle.graal.compiler.amd64", + "com.oracle.graal.hotspot.amd64", + #endif + "com.oracle.graal.api.runtime", + "com.oracle.graal.api.meta", + "com.oracle.graal.api.code", + "com.oracle.graal.api.interpreter", + "com.oracle.graal.hotspot", + "com.oracle.graal.asm", + "com.oracle.graal.alloc", + "com.oracle.graal.snippets", + "com.oracle.graal.compiler", + "com.oracle.graal.loop", + "com.oracle.graal.phases", + "com.oracle.graal.phases.common", + "com.oracle.graal.virtual", + "com.oracle.graal.nodes", + "com.oracle.graal.printer", + "com.oracle.graal.debug", + "com.oracle.graal.graph", + "com.oracle.graal.lir", + "com.oracle.graal.bytecode", + "com.oracle.graal.java" + }; + + const int len = sizeof(graal_projects) / sizeof(char*); + for (int i = 0; i < len; i++) { + if (PrintVMOptions) { + tty->print_cr("Adding project directory %s to bootclasspath", graal_projects[i]); + } + prepend_to_graal_classpath(scp_compiler, graal_dir, graal_projects[i]); } } - if (PrintVMOptions) tty->print_cr("GRAAL=%s", graal_dir); - - // this declaration is checked for correctness by 'mx build' - only - // modify its entries, not its name or shape - const char* graal_projects[] = { -#ifdef AMD64 - "com.oracle.graal.amd64", - "com.oracle.graal.asm.amd64", - "com.oracle.graal.lir.amd64", - "com.oracle.graal.compiler.amd64", - "com.oracle.graal.hotspot.amd64", -#endif - "com.oracle.graal.api.runtime", - "com.oracle.graal.api.meta", - "com.oracle.graal.api.code", - "com.oracle.graal.api.interpreter", - "com.oracle.graal.hotspot", - "com.oracle.graal.asm", - "com.oracle.graal.alloc", - "com.oracle.graal.snippets", - "com.oracle.graal.compiler", - "com.oracle.graal.loop", - "com.oracle.graal.phases", - "com.oracle.graal.phases.common", - "com.oracle.graal.virtual", - "com.oracle.graal.nodes", - "com.oracle.graal.printer", - "com.oracle.graal.debug", - "com.oracle.graal.graph", - "com.oracle.graal.lir", - "com.oracle.graal.bytecode", - "com.oracle.graal.java" - }; - - SysClassPath scp_compiler(""); - const int len = sizeof(graal_projects) / sizeof(char*); - for (int i = 0; i < len; i++) { - if (PrintVMOptions) { - tty->print_cr("Adding project directory %s to bootclasspath", graal_projects[i]); - } - prepend_to_graal_classpath(scp_compiler, graal_dir, graal_projects[i]); - } + scp_compiler.expand_endorsed(); - Arguments::set_compilerclasspath(scp_compiler.combined_path()); + #endif if (AggressiveOpts) { diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/runtime/compilationPolicy.cpp --- a/src/share/vm/runtime/compilationPolicy.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/runtime/compilationPolicy.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -460,7 +460,15 @@ } } } + if (!m->queued_for_compilation()) { + if (TraceCompilationPolicy) { + tty->print("method invocation trigger: "); + m->print_short_name(tty); + tty->print_cr(" ( interpreted " INTPTR_FORMAT ", size=%d, hotCount=%d, hotTime=" UINT64_FORMAT " ) ", (address)m(), m->code_size(), hot_count, hot_time); + } + + assert(m->is_native() || m->method_data() != NULL, "do not compile code methods"); CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier, m, hot_count, "count", thread); } } diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/runtime/globals.hpp --- a/src/share/vm/runtime/globals.hpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/runtime/globals.hpp Thu Nov 15 11:40:50 2012 +0100 @@ -2612,6 +2612,9 @@ diagnostic(bool, PrintInterpreter, false, \ "Prints the generated interpreter code") \ \ + product(bool, PrintMachineCodeToFile, false, \ + "Prints the generated machine code to a file (int + comp)") \ + \ product(bool, UseInterpreter, true, \ "Use interpreter for non-compiled methods") \ \ diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/runtime/init.cpp --- a/src/share/vm/runtime/init.cpp Tue Nov 13 21:21:02 2012 +0100 +++ b/src/share/vm/runtime/init.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -34,6 +34,7 @@ #include "runtime/init.hpp" #include "runtime/safepoint.hpp" #include "runtime/sharedRuntime.hpp" +#include "utilities/machineCodePrinter.hpp" // Initialization done by VM thread in vm_init_globals() void check_ThreadShadow(); @@ -86,6 +87,10 @@ mutex_init(); chunkpool_init(); perfMemory_init(); + + if(PrintMachineCodeToFile) { + MachineCodePrinter::initialize(); + } } diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/utilities/machineCodePrinter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/utilities/machineCodePrinter.cpp Thu Nov 15 11:40:50 2012 +0100 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "precompiled.hpp" +#include "utilities/machineCodePrinter.hpp" +#include "utilities/ostream.hpp" + +fileStream* MachineCodePrinter::_st = NULL; +volatile int MachineCodePrinter::_write_lock = 0; + +void MachineCodePrinter::initialize() { + _st = new (ResourceObj::C_HEAP, mtInternal) fileStream("machineCode.txt"); +} + +void MachineCodePrinter::print(nmethod* nm) { + lock(); + Disassembler::decode(nm, _st); + unlock(); +} + +void MachineCodePrinter::print(CodeBlob* cb) { + lock(); + Disassembler::decode(cb, _st); + unlock(); +} + +void MachineCodePrinter::print(StubQueue* stub_queue) { + lock(); + stub_queue->print_on(_st); + unlock(); +} + +void MachineCodePrinter::flush() { + _st->flush(); +} + +void MachineCodePrinter::lock() { + Thread::SpinAcquire(&_write_lock, "Put"); +} + +void MachineCodePrinter::unlock() { + Thread::SpinRelease(&_write_lock); +} diff -r 5bbe9618118e -r 8c5333c80cfd src/share/vm/utilities/machineCodePrinter.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/utilities/machineCodePrinter.hpp Thu Nov 15 11:40:50 2012 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#ifndef SHARE_VM_UTILITIES_MACHINE_CODE_PRINTER_HPP +#define SHARE_VM_UTILITIES_MACHINE_CODE_PRINTER_HPP + +class MachineCodePrinter : public AllStatic { +private: + static fileStream* _st; + static volatile int _write_lock; + +public: + static void initialize(); + static void print(nmethod* nm); + static void print(CodeBlob* cb); + static void print(StubQueue* stub_queue); + static void flush(); + +private: + static void lock(); + static void unlock(); +}; + +#endif // SHARE_VM_UTILITIES_MACHINE_CODE_PRINTER_HPP