comparison src/share/vm/opto/compile.hpp @ 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 f2110083203d
children edb5ab0f3fe5
comparison
equal deleted inserted replaced
10086:e0fb8a213650 10408:836a62f43af9
1 /* 1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 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.
34 #include "libadt/dict.hpp" 34 #include "libadt/dict.hpp"
35 #include "libadt/port.hpp" 35 #include "libadt/port.hpp"
36 #include "libadt/vectset.hpp" 36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp" 37 #include "memory/resourceArea.hpp"
38 #include "opto/idealGraphPrinter.hpp" 38 #include "opto/idealGraphPrinter.hpp"
39 #include "opto/phasetype.hpp"
39 #include "opto/phase.hpp" 40 #include "opto/phase.hpp"
40 #include "opto/regmask.hpp" 41 #include "opto/regmask.hpp"
41 #include "runtime/deoptimization.hpp" 42 #include "runtime/deoptimization.hpp"
42 #include "runtime/vmThread.hpp" 43 #include "runtime/vmThread.hpp"
44 #include "trace/tracing.hpp"
43 45
44 class Block; 46 class Block;
45 class Bundle; 47 class Bundle;
46 class C2Compiler; 48 class C2Compiler;
47 class CallGenerator; 49 class CallGenerator;
260 // Fixed parameters to this compilation. 262 // Fixed parameters to this compilation.
261 const int _compile_id; 263 const int _compile_id;
262 const bool _save_argument_registers; // save/restore arg regs for trampolines 264 const bool _save_argument_registers; // save/restore arg regs for trampolines
263 const bool _subsume_loads; // Load can be matched as part of a larger op. 265 const bool _subsume_loads; // Load can be matched as part of a larger op.
264 const bool _do_escape_analysis; // Do escape analysis. 266 const bool _do_escape_analysis; // Do escape analysis.
267 const bool _eliminate_boxing; // Do boxing elimination.
265 ciMethod* _method; // The method being compiled. 268 ciMethod* _method; // The method being compiled.
266 int _entry_bci; // entry bci for osr methods. 269 int _entry_bci; // entry bci for osr methods.
267 const TypeFunc* _tf; // My kind of signature 270 const TypeFunc* _tf; // My kind of signature
268 InlineTree* _ilt; // Ditto (temporary). 271 InlineTree* _ilt; // Ditto (temporary).
269 address _stub_function; // VM entry for stub being compiled, or NULL 272 address _stub_function; // VM entry for stub being compiled, or NULL
285 bool _inlining_incrementally;// Are we doing incremental inlining (post parse) 288 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
286 bool _has_loops; // True if the method _may_ have some loops 289 bool _has_loops; // True if the method _may_ have some loops
287 bool _has_split_ifs; // True if the method _may_ have some split-if 290 bool _has_split_ifs; // True if the method _may_ have some split-if
288 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores. 291 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
289 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated 292 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
293 bool _has_boxed_value; // True if a boxed object is allocated
290 int _max_vector_size; // Maximum size of generated vectors 294 int _max_vector_size; // Maximum size of generated vectors
291 uint _trap_hist[trapHistLength]; // Cumulative traps 295 uint _trap_hist[trapHistLength]; // Cumulative traps
292 bool _trap_can_recompile; // Have we emitted a recompiling trap? 296 bool _trap_can_recompile; // Have we emitted a recompiling trap?
293 uint _decompile_count; // Cumulative decompilation counts. 297 uint _decompile_count; // Cumulative decompilation counts.
294 bool _do_inlining; // True if we intend to do inlining 298 bool _do_inlining; // True if we intend to do inlining
318 ConnectionGraph* _congraph; 322 ConnectionGraph* _congraph;
319 #ifndef PRODUCT 323 #ifndef PRODUCT
320 IdealGraphPrinter* _printer; 324 IdealGraphPrinter* _printer;
321 #endif 325 #endif
322 326
327
323 // Node management 328 // Node management
324 uint _unique; // Counter for unique Node indices 329 uint _unique; // Counter for unique Node indices
325 VectorSet _dead_node_list; // Set of dead nodes 330 VectorSet _dead_node_list; // Set of dead nodes
326 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N). 331 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
327 // So use this to keep count and make the call O(1). 332 // So use this to keep count and make the call O(1).
372 WarmCallInfo* _warm_calls; // Sorted work-list for heat-based inlining. 377 WarmCallInfo* _warm_calls; // Sorted work-list for heat-based inlining.
373 378
374 GrowableArray<CallGenerator*> _late_inlines; // List of CallGenerators to be revisited after 379 GrowableArray<CallGenerator*> _late_inlines; // List of CallGenerators to be revisited after
375 // main parsing has finished. 380 // main parsing has finished.
376 GrowableArray<CallGenerator*> _string_late_inlines; // same but for string operations 381 GrowableArray<CallGenerator*> _string_late_inlines; // same but for string operations
382
383 GrowableArray<CallGenerator*> _boxing_late_inlines; // same but for boxing operations
377 384
378 int _late_inlines_pos; // Where in the queue should the next late inlining candidate go (emulate depth first inlining) 385 int _late_inlines_pos; // Where in the queue should the next late inlining candidate go (emulate depth first inlining)
379 uint _number_of_mh_late_inlines; // number of method handle late inlining still pending 386 uint _number_of_mh_late_inlines; // number of method handle late inlining still pending
380 387
381 388
484 491
485 // Does this compilation allow instructions to subsume loads? User 492 // Does this compilation allow instructions to subsume loads? User
486 // instructions that subsume a load may result in an unschedulable 493 // instructions that subsume a load may result in an unschedulable
487 // instruction sequence. 494 // instruction sequence.
488 bool subsume_loads() const { return _subsume_loads; } 495 bool subsume_loads() const { return _subsume_loads; }
489 // Do escape analysis. 496 /** Do escape analysis. */
490 bool do_escape_analysis() const { return _do_escape_analysis; } 497 bool do_escape_analysis() const { return _do_escape_analysis; }
498 /** Do boxing elimination. */
499 bool eliminate_boxing() const { return _eliminate_boxing; }
500 /** Do aggressive boxing elimination. */
501 bool aggressive_unboxing() const { return _eliminate_boxing && AggressiveUnboxing; }
491 bool save_argument_registers() const { return _save_argument_registers; } 502 bool save_argument_registers() const { return _save_argument_registers; }
492 503
493 504
494 // Other fixed compilation parameters. 505 // Other fixed compilation parameters.
495 ciMethod* method() const { return _method; } 506 ciMethod* method() const { return _method; }
525 void set_has_split_ifs(bool z) { _has_split_ifs = z; } 536 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
526 bool has_unsafe_access() const { return _has_unsafe_access; } 537 bool has_unsafe_access() const { return _has_unsafe_access; }
527 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; } 538 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
528 bool has_stringbuilder() const { return _has_stringbuilder; } 539 bool has_stringbuilder() const { return _has_stringbuilder; }
529 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; } 540 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
541 bool has_boxed_value() const { return _has_boxed_value; }
542 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
530 int max_vector_size() const { return _max_vector_size; } 543 int max_vector_size() const { return _max_vector_size; }
531 void set_max_vector_size(int s) { _max_vector_size = s; } 544 void set_max_vector_size(int s) { _max_vector_size = s; }
532 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; } 545 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
533 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; } 546 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
534 bool trap_can_recompile() const { return _trap_can_recompile; } 547 bool trap_can_recompile() const { return _trap_can_recompile; }
561 574
562 // JSR 292 575 // JSR 292
563 bool has_method_handle_invokes() const { return _has_method_handle_invokes; } 576 bool has_method_handle_invokes() const { return _has_method_handle_invokes; }
564 void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; } 577 void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; }
565 578
579 jlong _latest_stage_start_counter;
580
566 void begin_method() { 581 void begin_method() {
567 #ifndef PRODUCT 582 #ifndef PRODUCT
568 if (_printer) _printer->begin_method(this); 583 if (_printer) _printer->begin_method(this);
569 #endif 584 #endif
570 } 585 C->_latest_stage_start_counter = os::elapsed_counter();
571 void print_method(const char * name, int level = 1) { 586 }
587
588 void print_method(CompilerPhaseType cpt, int level = 1) {
589 EventCompilerPhase event(UNTIMED);
590 if (event.should_commit()) {
591 event.set_starttime(C->_latest_stage_start_counter);
592 event.set_endtime(os::elapsed_counter());
593 event.set_phase((u1) cpt);
594 event.set_compileID(C->_compile_id);
595 event.set_phaseLevel(level);
596 event.commit();
597 }
598
599
572 #ifndef PRODUCT 600 #ifndef PRODUCT
573 if (_printer) _printer->print_method(this, name, level); 601 if (_printer) _printer->print_method(this, CompilerPhaseTypeHelper::to_string(cpt), level);
574 #endif 602 #endif
575 } 603 C->_latest_stage_start_counter = os::elapsed_counter();
576 void end_method() { 604 }
605
606 void end_method(int level = 1) {
607 EventCompilerPhase event(UNTIMED);
608 if (event.should_commit()) {
609 event.set_starttime(C->_latest_stage_start_counter);
610 event.set_endtime(os::elapsed_counter());
611 event.set_phase((u1) PHASE_END);
612 event.set_compileID(C->_compile_id);
613 event.set_phaseLevel(level);
614 event.commit();
615 }
577 #ifndef PRODUCT 616 #ifndef PRODUCT
578 if (_printer) _printer->end_method(); 617 if (_printer) _printer->end_method();
579 #endif 618 #endif
580 } 619 }
581 620
582 int macro_count() { return _macro_nodes->length(); } 621 int macro_count() const { return _macro_nodes->length(); }
583 int predicate_count() { return _predicate_opaqs->length();} 622 int predicate_count() const { return _predicate_opaqs->length();}
584 int expensive_count() { return _expensive_nodes->length(); } 623 int expensive_count() const { return _expensive_nodes->length(); }
585 Node* macro_node(int idx) { return _macro_nodes->at(idx); } 624 Node* macro_node(int idx) const { return _macro_nodes->at(idx); }
586 Node* predicate_opaque1_node(int idx) { return _predicate_opaqs->at(idx);} 625 Node* predicate_opaque1_node(int idx) const { return _predicate_opaqs->at(idx);}
587 Node* expensive_node(int idx) { return _expensive_nodes->at(idx); } 626 Node* expensive_node(int idx) const { return _expensive_nodes->at(idx); }
588 ConnectionGraph* congraph() { return _congraph;} 627 ConnectionGraph* congraph() { return _congraph;}
589 void set_congraph(ConnectionGraph* congraph) { _congraph = congraph;} 628 void set_congraph(ConnectionGraph* congraph) { _congraph = congraph;}
590 void add_macro_node(Node * n) { 629 void add_macro_node(Node * n) {
591 //assert(n->is_macro(), "must be a macro node"); 630 //assert(n->is_macro(), "must be a macro node");
592 assert(!_macro_nodes->contains(n), " duplicate entry in expand list"); 631 assert(!_macro_nodes->contains(n), " duplicate entry in expand list");
764 JVMState* build_start_state(StartNode* start, const TypeFunc* tf); 803 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
765 804
766 // Decide how to build a call. 805 // Decide how to build a call.
767 // The profile factor is a discount to apply to this site's interp. profile. 806 // The profile factor is a discount to apply to this site's interp. profile.
768 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch, JVMState* jvms, bool allow_inline, float profile_factor, bool allow_intrinsics = true, bool delayed_forbidden = false); 807 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch, JVMState* jvms, bool allow_inline, float profile_factor, bool allow_intrinsics = true, bool delayed_forbidden = false);
769 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms); 808 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
809 return should_delay_string_inlining(call_method, jvms) ||
810 should_delay_boxing_inlining(call_method, jvms);
811 }
812 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
813 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
770 814
771 // Helper functions to identify inlining potential at call-site 815 // Helper functions to identify inlining potential at call-site
772 ciMethod* optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass, 816 ciMethod* optimize_virtual_call(ciMethod* caller, int bci, ciInstanceKlass* klass,
773 ciMethod* callee, const TypeOopPtr* receiver_type, 817 ciMethod* callee, const TypeOopPtr* receiver_type,
774 bool is_virtual, 818 bool is_virtual,
820 864
821 void add_string_late_inline(CallGenerator* cg) { 865 void add_string_late_inline(CallGenerator* cg) {
822 _string_late_inlines.push(cg); 866 _string_late_inlines.push(cg);
823 } 867 }
824 868
869 void add_boxing_late_inline(CallGenerator* cg) {
870 _boxing_late_inlines.push(cg);
871 }
872
825 void remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful); 873 void remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful);
826 874
827 void dump_inlining(); 875 void dump_inlining();
828 876
829 bool over_inlining_cutoff() const { 877 bool over_inlining_cutoff() const {
839 bool has_mh_late_inlines() const { return _number_of_mh_late_inlines > 0; } 887 bool has_mh_late_inlines() const { return _number_of_mh_late_inlines > 0; }
840 888
841 void inline_incrementally_one(PhaseIterGVN& igvn); 889 void inline_incrementally_one(PhaseIterGVN& igvn);
842 void inline_incrementally(PhaseIterGVN& igvn); 890 void inline_incrementally(PhaseIterGVN& igvn);
843 void inline_string_calls(bool parse_time); 891 void inline_string_calls(bool parse_time);
892 void inline_boxing_calls(PhaseIterGVN& igvn);
844 893
845 // Matching, CFG layout, allocation, code generation 894 // Matching, CFG layout, allocation, code generation
846 PhaseCFG* cfg() { return _cfg; } 895 PhaseCFG* cfg() { return _cfg; }
847 bool select_24_bit_instr() const { return _select_24_bit_instr; } 896 bool select_24_bit_instr() const { return _select_24_bit_instr; }
848 bool in_24_bit_fp_mode() const { return _in_24_bit_fp_mode; } 897 bool in_24_bit_fp_mode() const { return _in_24_bit_fp_mode; }
911 // Major entry point. Given a Scope, compile the associated method. 960 // Major entry point. Given a Scope, compile the associated method.
912 // For normal compilations, entry_bci is InvocationEntryBci. For on stack 961 // For normal compilations, entry_bci is InvocationEntryBci. For on stack
913 // replacement, entry_bci indicates the bytecode for which to compile a 962 // replacement, entry_bci indicates the bytecode for which to compile a
914 // continuation. 963 // continuation.
915 Compile(ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, 964 Compile(ciEnv* ci_env, C2Compiler* compiler, ciMethod* target,
916 int entry_bci, bool subsume_loads, bool do_escape_analysis); 965 int entry_bci, bool subsume_loads, bool do_escape_analysis,
966 bool eliminate_boxing);
917 967
918 // Second major entry point. From the TypeFunc signature, generate code 968 // Second major entry point. From the TypeFunc signature, generate code
919 // to pass arguments from the Java calling convention to the C calling 969 // to pass arguments from the Java calling convention to the C calling
920 // convention. 970 // convention.
921 Compile(ciEnv* ci_env, const TypeFunc *(*gen)(), 971 Compile(ciEnv* ci_env, const TypeFunc *(*gen)(),