# HG changeset patch # User mdoerr # Date 1445420405 -7200 # Node ID 36696908d3d37268252aece29d80202b135b8e55 # Parent daf8acf3afdab4da6795138194cf064ff5910c7e 8138892: C1: Improve counter overflow checking Reviewed-by: iveresov, goetz, twisti diff --git a/src/cpu/aarch64/vm/c1_CodeStubs_aarch64.cpp b/src/cpu/aarch64/vm/c1_CodeStubs_aarch64.cpp --- a/src/cpu/aarch64/vm/c1_CodeStubs_aarch64.cpp +++ b/src/cpu/aarch64/vm/c1_CodeStubs_aarch64.cpp @@ -41,7 +41,9 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) { __ bind(_entry); - ce->store_parameter(_method->as_register(), 1); + Metadata *m = _method->as_constant_ptr()->as_metadata(); + __ mov_metadata(rscratch1, m); + ce->store_parameter(rscratch1, 1); ce->store_parameter(_bci, 0); __ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id))); ce->add_call_info_here(_info); diff --git a/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp b/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp --- a/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp +++ b/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp @@ -94,8 +94,10 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) { __ bind(_entry); __ set(_bci, G4); + Metadata *m = _method->as_constant_ptr()->as_metadata(); + __ set_metadata_constant(m, G5); __ call(Runtime1::entry_for(Runtime1::counter_overflow_id), relocInfo::runtime_call_type); - __ delayed()->mov_or_nop(_method->as_register(), G5); + __ delayed()->nop(); ce->add_call_info_here(_info); ce->verify_oop_map(_info); diff --git a/src/cpu/x86/vm/c1_CodeStubs_x86.cpp b/src/cpu/x86/vm/c1_CodeStubs_x86.cpp --- a/src/cpu/x86/vm/c1_CodeStubs_x86.cpp +++ b/src/cpu/x86/vm/c1_CodeStubs_x86.cpp @@ -81,7 +81,8 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) { __ bind(_entry); - ce->store_parameter(_method->as_register(), 1); + Metadata *m = _method->as_constant_ptr()->as_metadata(); + ce->store_parameter(m, 1); ce->store_parameter(_bci, 0); __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id))); ce->add_call_info_here(_info); diff --git a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp --- a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp @@ -3054,6 +3054,14 @@ } +void LIR_Assembler::store_parameter(Metadata* m, int offset_from_rsp_in_words) { + assert(offset_from_rsp_in_words >= 0, "invalid offset from rsp"); + int offset_from_rsp_in_bytes = offset_from_rsp_in_words * BytesPerWord; + assert(offset_from_rsp_in_bytes < frame_map()->reserved_argument_area_size(), "invalid offset"); + __ mov_metadata(Address(rsp, offset_from_rsp_in_bytes), m); +} + + // This code replaces a call to arraycopy; no exception may // be thrown in this code, they must be thrown in the System.arraycopy // activation frame; we could save some checks if this would not be the case diff --git a/src/cpu/x86/vm/c1_LIRAssembler_x86.hpp b/src/cpu/x86/vm/c1_LIRAssembler_x86.hpp --- a/src/cpu/x86/vm/c1_LIRAssembler_x86.hpp +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -49,9 +49,10 @@ Register recv, Label* update_done); public: - void store_parameter(Register r, int offset_from_esp_in_words); - void store_parameter(jint c, int offset_from_esp_in_words); - void store_parameter(jobject c, int offset_from_esp_in_words); + void store_parameter(Register r, int offset_from_esp_in_words); + void store_parameter(jint c, int offset_from_esp_in_words); + void store_parameter(jobject c, int offset_from_esp_in_words); + void store_parameter(Metadata* c, int offset_from_esp_in_words); enum { call_stub_size = NOT_LP64(15) LP64_ONLY(28), exception_handler_size = DEBUG_ONLY(1*K) NOT_DEBUG(175), diff --git a/src/share/vm/c1/c1_LIRGenerator.cpp b/src/share/vm/c1/c1_LIRGenerator.cpp --- a/src/share/vm/c1/c1_LIRGenerator.cpp +++ b/src/share/vm/c1/c1_LIRGenerator.cpp @@ -3418,14 +3418,18 @@ __ add(result, LIR_OprFact::intConst(InvocationCounter::count_increment), result); __ store(result, counter); if (notify) { - LIR_Opr mask = load_immediate(frequency << InvocationCounter::count_shift, T_INT); - LIR_Opr meth = new_register(T_METADATA); - __ metadata2reg(method->constant_encoding(), meth); - __ logical_and(result, mask, result); - __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0)); + LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding()); // The bci for info can point to cmp for if's we want the if bci CodeStub* overflow = new CounterOverflowStub(info, bci, meth); - __ branch(lir_cond_equal, T_INT, overflow); + int freq = frequency << InvocationCounter::count_shift; + if (freq == 0) { + __ branch(lir_cond_always, T_ILLEGAL, overflow); + } else { + LIR_Opr mask = load_immediate(freq, T_INT); + __ logical_and(result, mask, result); + __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0)); + __ branch(lir_cond_equal, T_INT, overflow); + } __ branch_destination(overflow->continuation()); } }