--- old/src/share/vm/opto/library_call.cpp 2015-01-21 14:39:30.000000000 +0300 +++ new/src/share/vm/opto/library_call.cpp 2015-01-21 14:39:30.000000000 +0300 @@ -41,6 +41,7 @@ #include "opto/movenode.hpp" #include "opto/mulnode.hpp" #include "opto/narrowptrnode.hpp" +#include "opto/opaquenode.hpp" #include "opto/parse.hpp" #include "opto/runtime.hpp" #include "opto/subnode.hpp" @@ -287,6 +288,8 @@ bool inline_updateBytesCRC32(); bool inline_updateByteBufferCRC32(); bool inline_multiplyToLen(); + + bool inline_profileBranch(); }; @@ -900,6 +903,9 @@ case vmIntrinsics::_updateByteBufferCRC32: return inline_updateByteBufferCRC32(); + case vmIntrinsics::_profileBranch: + return inline_profileBranch(); + default: // If you get here, it may be that someone has added a new intrinsic // to the list in vmSymbols.hpp without implementing it here. @@ -5873,3 +5879,44 @@ return instof_false; // even if it is NULL } + +bool LibraryCallKit::inline_profileBranch() { + Node* counts = argument(1); + const TypeAryPtr* ary = NULL; + ciArray* aobj = NULL; + if (counts->is_Con() + && (ary = counts->bottom_type()->isa_aryptr()) != NULL + && (aobj = ary->const_oop()->as_array()) != NULL + && (aobj->length() == 2)) { + jint taken = aobj->element_value(1).as_int(); + jint not_taken = aobj->element_value(0).as_int(); + + if (C->log() != NULL) { + C->log()->elem("observe source='profileBranch' taken='%d' not_taken='%d'", + taken, not_taken); + } + + if (taken + not_taken == 0) { + // According to profile, never executed. + uncommon_trap_exact(Deoptimization::Reason_intrinsic, + Deoptimization::Action_reinterpret); + return true; + } + // Stop profiling. + // MethodHandleImpl::profileBranch() has profiling logic in it's bytecode. + // By replacing method's body with profile data (represented as ProfileBranchNode + // on IR level) we effectively disable profiling. + // It enables full speed execution once optimized code is generated. + Node* profile = _gvn.transform(new ProfileBranchNode(argument(0), taken, not_taken)); + C->record_for_igvn(profile); + set_result(profile); + return true; + } else { + // Continue profiling. + // Profile data isn't available at the moment. So, execute method's bytecode version. + // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod + // is compiled and counters aren't available since corresponding MethodHandle + // isn't a compile-time constant. + return false; + } +}