Path: blob/master/src/hotspot/share/gc/shenandoah/c1/shenandoahBarrierSetC1.hpp
40975 views
/*1* Copyright (c) 2018, 2021, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP25#define SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP2627#include "c1/c1_CodeStubs.hpp"28#include "gc/shared/c1/barrierSetC1.hpp"2930class ShenandoahPreBarrierStub: public CodeStub {31friend class ShenandoahBarrierSetC1;32private:33bool _do_load;34LIR_Opr _addr;35LIR_Opr _pre_val;36LIR_PatchCode _patch_code;37CodeEmitInfo* _info;3839public:40// Version that _does_ generate a load of the previous value from addr.41// addr (the address of the field to be read) must be a LIR_Address42// pre_val (a temporary register) must be a register;43ShenandoahPreBarrierStub(LIR_Opr addr, LIR_Opr pre_val, LIR_PatchCode patch_code, CodeEmitInfo* info) :44_do_load(true), _addr(addr), _pre_val(pre_val),45_patch_code(patch_code), _info(info)46{47assert(_pre_val->is_register(), "should be temporary register");48assert(_addr->is_address(), "should be the address of the field");49}5051// Version that _does not_ generate load of the previous value; the52// previous value is assumed to have already been loaded into pre_val.53ShenandoahPreBarrierStub(LIR_Opr pre_val) :54_do_load(false), _addr(LIR_OprFact::illegalOpr), _pre_val(pre_val),55_patch_code(lir_patch_none), _info(NULL)56{57assert(_pre_val->is_register(), "should be a register");58}5960LIR_Opr addr() const { return _addr; }61LIR_Opr pre_val() const { return _pre_val; }62LIR_PatchCode patch_code() const { return _patch_code; }63CodeEmitInfo* info() const { return _info; }64bool do_load() const { return _do_load; }6566virtual void emit_code(LIR_Assembler* e);67virtual void visit(LIR_OpVisitState* visitor) {68if (_do_load) {69// don't pass in the code emit info since it's processed in the fast70// path71if (_info != NULL)72visitor->do_slow_case(_info);73else74visitor->do_slow_case();7576visitor->do_input(_addr);77visitor->do_temp(_pre_val);78} else {79visitor->do_slow_case();80visitor->do_input(_pre_val);81}82}83#ifndef PRODUCT84virtual void print_name(outputStream* out) const { out->print("ShenandoahPreBarrierStub"); }85#endif // PRODUCT86};8788class ShenandoahLoadReferenceBarrierStub: public CodeStub {89friend class ShenandoahBarrierSetC1;90private:91LIR_Opr _obj;92LIR_Opr _addr;93LIR_Opr _result;94LIR_Opr _tmp1;95LIR_Opr _tmp2;96DecoratorSet _decorators;97public:98ShenandoahLoadReferenceBarrierStub(LIR_Opr obj, LIR_Opr addr, LIR_Opr result, LIR_Opr tmp1, LIR_Opr tmp2, DecoratorSet decorators) :99_obj(obj), _addr(addr), _result(result), _tmp1(tmp1), _tmp2(tmp2), _decorators(decorators)100{101assert(_obj->is_register(), "should be register");102assert(_addr->is_register(), "should be register");103assert(_result->is_register(), "should be register");104assert(_tmp1->is_register(), "should be register");105assert(_tmp2->is_register(), "should be register");106}107108LIR_Opr obj() const { return _obj; }109LIR_Opr addr() const { return _addr; }110LIR_Opr result() const { return _result; }111LIR_Opr tmp1() const { return _tmp1; }112LIR_Opr tmp2() const { return _tmp2; }113DecoratorSet decorators() const { return _decorators; }114115virtual void emit_code(LIR_Assembler* e);116virtual void visit(LIR_OpVisitState* visitor) {117visitor->do_slow_case();118visitor->do_input(_obj);119visitor->do_temp(_obj);120visitor->do_input(_addr);121visitor->do_temp(_addr);122visitor->do_temp(_result);123visitor->do_temp(_tmp1);124visitor->do_temp(_tmp2);125}126#ifndef PRODUCT127virtual void print_name(outputStream* out) const { out->print("ShenandoahLoadReferenceBarrierStub"); }128#endif // PRODUCT129};130131class LIR_OpShenandoahCompareAndSwap : public LIR_Op {132friend class LIR_OpVisitState;133134private:135LIR_Opr _addr;136LIR_Opr _cmp_value;137LIR_Opr _new_value;138LIR_Opr _tmp1;139LIR_Opr _tmp2;140141public:142LIR_OpShenandoahCompareAndSwap(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,143LIR_Opr t1, LIR_Opr t2, LIR_Opr result)144: LIR_Op(lir_none, result, NULL) // no info145, _addr(addr)146, _cmp_value(cmp_value)147, _new_value(new_value)148, _tmp1(t1)149, _tmp2(t2) { }150151LIR_Opr addr() const { return _addr; }152LIR_Opr cmp_value() const { return _cmp_value; }153LIR_Opr new_value() const { return _new_value; }154LIR_Opr tmp1() const { return _tmp1; }155LIR_Opr tmp2() const { return _tmp2; }156157virtual void visit(LIR_OpVisitState* state) {158assert(_addr->is_valid(), "used");159assert(_cmp_value->is_valid(), "used");160assert(_new_value->is_valid(), "used");161if (_info) state->do_info(_info);162state->do_input(_addr);163state->do_temp(_addr);164state->do_input(_cmp_value);165state->do_temp(_cmp_value);166state->do_input(_new_value);167state->do_temp(_new_value);168if (_tmp1->is_valid()) state->do_temp(_tmp1);169if (_tmp2->is_valid()) state->do_temp(_tmp2);170if (_result->is_valid()) state->do_output(_result);171}172173virtual void emit_code(LIR_Assembler* masm);174175virtual void print_instr(outputStream* out) const {176addr()->print(out); out->print(" ");177cmp_value()->print(out); out->print(" ");178new_value()->print(out); out->print(" ");179tmp1()->print(out); out->print(" ");180tmp2()->print(out); out->print(" ");181}182#ifndef PRODUCT183virtual const char* name() const {184return "shenandoah_cas_obj";185}186#endif // PRODUCT187};188189class ShenandoahBarrierSetC1 : public BarrierSetC1 {190private:191CodeBlob* _pre_barrier_c1_runtime_code_blob;192CodeBlob* _load_reference_barrier_strong_rt_code_blob;193CodeBlob* _load_reference_barrier_strong_native_rt_code_blob;194CodeBlob* _load_reference_barrier_weak_rt_code_blob;195CodeBlob* _load_reference_barrier_phantom_rt_code_blob;196197void pre_barrier(LIRGenerator* gen, CodeEmitInfo* info, DecoratorSet decorators, LIR_Opr addr_opr, LIR_Opr pre_val);198199LIR_Opr load_reference_barrier(LIRGenerator* gen, LIR_Opr obj, LIR_Opr addr, DecoratorSet decorators);200LIR_Opr iu_barrier(LIRGenerator* gen, LIR_Opr obj, CodeEmitInfo* info, DecoratorSet decorators);201202LIR_Opr load_reference_barrier_impl(LIRGenerator* gen, LIR_Opr obj, LIR_Opr addr, DecoratorSet decorators);203204LIR_Opr ensure_in_register(LIRGenerator* gen, LIR_Opr obj, BasicType type);205206public:207ShenandoahBarrierSetC1();208209CodeBlob* pre_barrier_c1_runtime_code_blob() {210assert(_pre_barrier_c1_runtime_code_blob != NULL, "");211return _pre_barrier_c1_runtime_code_blob;212}213214CodeBlob* load_reference_barrier_strong_rt_code_blob() {215assert(_load_reference_barrier_strong_rt_code_blob != NULL, "");216return _load_reference_barrier_strong_rt_code_blob;217}218219CodeBlob* load_reference_barrier_strong_native_rt_code_blob() {220assert(_load_reference_barrier_strong_native_rt_code_blob != NULL, "");221return _load_reference_barrier_strong_native_rt_code_blob;222}223224CodeBlob* load_reference_barrier_weak_rt_code_blob() {225assert(_load_reference_barrier_weak_rt_code_blob != NULL, "");226return _load_reference_barrier_weak_rt_code_blob;227}228229CodeBlob* load_reference_barrier_phantom_rt_code_blob() {230assert(_load_reference_barrier_phantom_rt_code_blob != NULL, "");231return _load_reference_barrier_phantom_rt_code_blob;232}233234protected:235236virtual void store_at_resolved(LIRAccess& access, LIR_Opr value);237virtual LIR_Opr resolve_address(LIRAccess& access, bool resolve_in_register);238virtual void load_at_resolved(LIRAccess& access, LIR_Opr result);239240virtual LIR_Opr atomic_cmpxchg_at_resolved(LIRAccess& access, LIRItem& cmp_value, LIRItem& new_value);241242virtual LIR_Opr atomic_xchg_at_resolved(LIRAccess& access, LIRItem& value);243244public:245246virtual void generate_c1_runtime_stubs(BufferBlob* buffer_blob);247};248249#endif // SHARE_GC_SHENANDOAH_C1_SHENANDOAHBARRIERSETC1_HPP250251252