8302369: Reduce the stack size of the C1 compiler

Reviewed-by: dlong
This commit is contained in:
sunguoyun 2023-02-20 19:28:09 +00:00 committed by Vladimir Kozlov
parent 0bf3a53e01
commit 36a0822633
20 changed files with 105 additions and 146 deletions

View File

@ -63,18 +63,6 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
__ b(_continuation);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
if (_info->deoptimize_on_exception()) {
@ -208,14 +196,6 @@ void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
assert(_result->as_register() == r0, "result must in r0");
__ b(_continuation);
}
// Implementation of MonitorAccessStubs
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg)
{
_info = new CodeEmitInfo(info);
}
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
assert(__ rsp_offset() == 0, "frame size should be fixed");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -82,4 +82,9 @@ enum {
pd_two_operand_lir_form = false
};
// the number of stack required by ArrayCopyStub
enum {
pd_arraycopystub_reserved_argument_area_size = 2
};
#endif // CPU_AARCH64_C1_DEFS_AARCH64_HPP

View File

@ -53,22 +53,6 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
__ b(_continuation);
}
// TODO: ARM - is it possible to inline these stubs into the main code stream?
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != nullptr, "must have info");
_info = new CodeEmitInfo(info);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != nullptr, "must have info");
_info = new CodeEmitInfo(info);
}
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
@ -192,16 +176,6 @@ void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
__ b(_continuation);
}
// Implementation of MonitorAccessStubs
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg)
{
_info = new CodeEmitInfo(info);
}
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
const Register obj_reg = _obj_reg->as_pointer_register();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -78,6 +78,11 @@ enum {
pd_two_operand_lir_form = false
};
// the number of stack required by ArrayCopyStub
enum {
pd_arraycopystub_reserved_argument_area_size = 2
};
#define PATCHED_ADDR (204)
#define CARDTABLEBARRIERSET_POST_BARRIER_HELPER

View File

@ -64,18 +64,6 @@ void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {
}
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
@ -282,13 +270,6 @@ void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
__ b(_continuation);
}
// Implementation of MonitorAccessStubs
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg) {
_info = new CodeEmitInfo(info);
}
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
address stub = Runtime1::entry_for(ce->compilation()->has_fpu_code() ? Runtime1::monitorenter_id : Runtime1::monitorenter_nofpu_id);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -77,4 +77,9 @@ enum {
pd_two_operand_lir_form = false
};
// the number of stack required by ArrayCopyStub
enum {
pd_arraycopystub_reserved_argument_area_size = 2
};
#endif // CPU_PPC_C1_DEFS_PPC_HPP

View File

@ -68,18 +68,6 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
__ j(_continuation);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
if (_info->deoptimize_on_exception()) {
@ -205,12 +193,6 @@ void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
__ j(_continuation);
}
// Implementation of MonitorAccessStubs
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg) {
_info = new CodeEmitInfo(info);
}
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
assert(__ rsp_offset() == 0, "frame size should be fixed");
__ bind(_entry);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, Huawei Technologies Co., Ltd. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -85,4 +85,9 @@ enum {
pd_two_operand_lir_form = false
};
// the number of stack required by ArrayCopyStub
enum {
pd_arraycopystub_reserved_argument_area_size = 2
};
#endif // CPU_RISCV_C1_DEFS_RISCV_HPP

View File

@ -45,18 +45,6 @@ void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {
ShouldNotReachHere();
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
if (_info->deoptimize_on_exception()) {
@ -227,11 +215,6 @@ void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
__ z_brul(_continuation);
}
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg) {
_info = new CodeEmitInfo(info);
}
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
Runtime1::StubID enter_id;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -72,4 +72,9 @@ enum {
pd_two_operand_lir_form = true
};
// the number of stack required by ArrayCopyStub
enum {
pd_arraycopystub_reserved_argument_area_size = 2
};
#endif // CPU_S390_C1_DEFS_S390_HPP

View File

@ -116,18 +116,6 @@ void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
__ jmp(_continuation);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
}
void RangeCheckStub::emit_code(LIR_Assembler* ce) {
__ bind(_entry);
if (_info->deoptimize_on_exception()) {
@ -254,16 +242,6 @@ void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
__ jmp(_continuation);
}
// Implementation of MonitorAccessStubs
MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg)
{
_info = new CodeEmitInfo(info);
}
void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
assert(__ rsp_offset() == 0, "frame size should be fixed");
__ bind(_entry);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, 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
@ -79,4 +79,9 @@ enum {
pd_two_operand_lir_form = true
};
// the number of stack required by ArrayCopyStub
enum {
pd_arraycopystub_reserved_argument_area_size = 5
};
#endif // CPU_X86_C1_DEFS_X86_HPP

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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
@ -110,6 +110,8 @@ class CounterOverflowStub: public CodeStub {
public:
CounterOverflowStub(CodeEmitInfo* info, int bci, LIR_Opr method) : _info(info), _bci(bci), _method(method) {
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
virtual void emit_code(LIR_Assembler* e);
@ -166,9 +168,21 @@ class RangeCheckStub: public CodeStub {
public:
// For ArrayIndexOutOfBoundsException.
RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array);
RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
: _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
// For IndexOutOfBoundsException.
RangeCheckStub(CodeEmitInfo* info, LIR_Opr index);
RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
: _index(index), _array(), _throw_index_out_of_bounds_exception(true) {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
virtual void emit_code(LIR_Assembler* e);
virtual CodeEmitInfo* info() const { return _info; }
virtual bool is_exception_throw_stub() const { return true; }
@ -335,7 +349,12 @@ class MonitorEnterStub: public MonitorAccessStub {
CodeEmitInfo* _info;
public:
MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info);
MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
: MonitorAccessStub(obj_reg, lock_reg) {
_info = new CodeEmitInfo(info);
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
virtual void emit_code(LIR_Assembler* e);
virtual CodeEmitInfo* info() const { return _info; }
@ -476,7 +495,10 @@ private:
public:
DeoptimizeStub(CodeEmitInfo* info, Deoptimization::DeoptReason reason, Deoptimization::DeoptAction action) :
_info(new CodeEmitInfo(info)), _trap_request(Deoptimization::make_trap_request(reason, action)) {}
_info(new CodeEmitInfo(info)), _trap_request(Deoptimization::make_trap_request(reason, action)) {
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
virtual void emit_code(LIR_Assembler* e);
virtual CodeEmitInfo* info() const { return _info; }
@ -499,6 +521,8 @@ class SimpleExceptionStub: public CodeStub {
public:
SimpleExceptionStub(Runtime1::StubID stub, LIR_Opr obj, CodeEmitInfo* info):
_obj(obj), _stub(stub), _info(info) {
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
void set_obj(LIR_Opr obj) {
@ -534,7 +558,10 @@ class ArrayCopyStub: public CodeStub {
LIR_OpArrayCopy* _op;
public:
ArrayCopyStub(LIR_OpArrayCopy* op): _op(op) { }
ArrayCopyStub(LIR_OpArrayCopy* op): _op(op) {
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(arraycopystub_reserved_argument_area_size * BytesPerWord);
}
LIR_Opr src() const { return _op->src(); }
LIR_Opr src_pos() const { return _op->src_pos(); }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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
@ -398,7 +398,7 @@ int Compilation::compile_java_method() {
{
PhaseTraceTime timeit(_t_emit_lir);
_frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack()));
_frame_map = new FrameMap(method(), hir()->number_of_locks(), hir()->max_stack());
emit_lir();
}
CHECK_BAILOUT_(no_frame_size);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, 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
@ -61,4 +61,9 @@ enum {
two_operand_lir_form = pd_two_operand_lir_form
};
// the number of stack required by ArrayCopyStub
enum {
arraycopystub_reserved_argument_area_size = pd_arraycopystub_reserved_argument_area_size
};
#endif // SHARE_C1_C1_DEFS_HPP

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2023, 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
@ -162,7 +162,11 @@ FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_si
assert(monitors >= 0, "not set");
_num_monitors = monitors;
assert(reserved_argument_area_size >= 0, "not set");
_reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
// reserved_argument_area_size does not include stack space that needs to be occupied in the stub
// and the stub will modify the value through update_reserved_argument_area_size(int size) if needed.
// see the constructor of class CounterOverflowStub for example.
_reserved_argument_area_size = reserved_argument_area_size * BytesPerWord;
_argcount = method->arg_size();
_argument_locations = new intArray(_argcount, _argcount, -1);

View File

@ -77,6 +77,11 @@ class FrameMap : public CompilationResourceObj {
spill_slot_size_in_bytes = 4
};
void update_reserved_argument_area_size (int size) {
assert(size >= 0, "check");
_reserved_argument_area_size = MAX2(_reserved_argument_area_size, size);
}
#include CPU_HEADER(c1_FrameMap)
friend class LIR_Opr;
@ -122,18 +127,12 @@ class FrameMap : public CompilationResourceObj {
_cpu_reg2rnr[reg->encoding()] = rnr;
}
void update_reserved_argument_area_size (int size) {
assert(size >= 0, "check");
_reserved_argument_area_size = MAX2(_reserved_argument_area_size, size);
}
protected:
#ifndef PRODUCT
static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); }
static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); }
#endif
ByteSize sp_offset_for_monitor_base(const int idx) const;
Address make_new_address(ByteSize sp_offset) const;

View File

@ -26,6 +26,7 @@
#define SHARE_GC_G1_C1_G1BARRIERSETC1_HPP
#include "c1/c1_CodeStubs.hpp"
#include "c1/c1_Compilation.hpp"
#include "gc/shared/c1/modRefBarrierSetC1.hpp"
class G1PreBarrierStub: public CodeStub {
@ -47,6 +48,8 @@ class G1PreBarrierStub: public CodeStub {
{
assert(_pre_val->is_register(), "should be temporary register");
assert(_addr->is_address(), "should be the address of the field");
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
// Version that _does not_ generate load of the previous value; the
@ -56,6 +59,8 @@ class G1PreBarrierStub: public CodeStub {
_patch_code(lir_patch_none), _info(NULL)
{
assert(_pre_val->is_register(), "should be a register");
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
LIR_Opr addr() const { return _addr; }
@ -94,7 +99,10 @@ class G1PostBarrierStub: public CodeStub {
public:
// addr (the address of the object head) and new_val must be registers.
G1PostBarrierStub(LIR_Opr addr, LIR_Opr new_val): _addr(addr), _new_val(new_val) { }
G1PostBarrierStub(LIR_Opr addr, LIR_Opr new_val): _addr(addr), _new_val(new_val) {
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
LIR_Opr addr() const { return _addr; }
LIR_Opr new_val() const { return _new_val; }

View File

@ -47,6 +47,8 @@ public:
{
assert(_pre_val->is_register(), "should be temporary register");
assert(_addr->is_address(), "should be the address of the field");
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
// Version that _does not_ generate load of the previous value; the
@ -104,6 +106,9 @@ public:
assert(_result->is_register(), "should be register");
assert(_tmp1->is_register(), "should be register");
assert(_tmp2->is_register(), "should be register");
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
LIR_Opr obj() const { return _obj; }

View File

@ -47,6 +47,9 @@ ZLoadBarrierStubC1::ZLoadBarrierStubC1(LIRAccess& access, LIR_Opr ref, address r
// Has index or displacement, need tmp register to load address into
_tmp = access.gen()->new_pointer_register();
}
FrameMap* f = Compilation::current()->frame_map();
f->update_reserved_argument_area_size(2 * BytesPerWord);
}
DecoratorSet ZLoadBarrierStubC1::decorators() const {