8138892: C1: Improve counter overflow checking
Reviewed-by: iveresov, goetz, twisti, vlivanov
--- a/hotspot/src/cpu/aarch64/vm/c1_CodeStubs_aarch64.cpp Fri Sep 18 13:41:24 2015 +0200
+++ b/hotspot/src/cpu/aarch64/vm/c1_CodeStubs_aarch64.cpp Wed Oct 21 11:40:05 2015 +0200
@@ -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);
--- a/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp Fri Sep 18 13:41:24 2015 +0200
+++ b/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp Wed Oct 21 11:40:05 2015 +0200
@@ -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);
--- a/hotspot/src/cpu/x86/vm/c1_CodeStubs_x86.cpp Fri Sep 18 13:41:24 2015 +0200
+++ b/hotspot/src/cpu/x86/vm/c1_CodeStubs_x86.cpp Wed Oct 21 11:40:05 2015 +0200
@@ -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);
--- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Fri Sep 18 13:41:24 2015 +0200
+++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Wed Oct 21 11:40:05 2015 +0200
@@ -2971,6 +2971,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
--- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.hpp Fri Sep 18 13:41:24 2015 +0200
+++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.hpp Wed Oct 21 11:40:05 2015 +0200
@@ -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),
--- a/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp Fri Sep 18 13:41:24 2015 +0200
+++ b/hotspot/src/share/vm/c1/c1_LIRGenerator.cpp Wed Oct 21 11:40:05 2015 +0200
@@ -3429,14 +3429,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());
}
}