Skip to content

Commit

Permalink
Verify stubs are generated in correct blob
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Nov 19, 2024
1 parent 932c715 commit d344a67
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8931,7 +8931,7 @@ class StubGenerator: public StubCodeGenerator {
}

public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/arm/stubGenerator_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3204,7 +3204,7 @@ class StubGenerator: public StubCodeGenerator {
}

public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/stubGenerator_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5023,7 +5023,7 @@ address generate_lookup_secondary_supers_table_stub(u1 super_klass_index) {
}

public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6610,7 +6610,7 @@ static const int64_t right_3_bits = right_n_bits(3);
}

public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/s390/stubGenerator_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3300,7 +3300,7 @@ class StubGenerator: public StubCodeGenerator {
}

public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/stubGenerator_x86_32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4300,7 +4300,7 @@ class StubGenerator: public StubCodeGenerator {


public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4412,7 +4412,7 @@ void StubGenerator::generate_compiler_stubs() {
#endif // COMPILER2_OR_JVMCI
}

StubGenerator::StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator::StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/zero/stubGenerator_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class StubGenerator: public StubCodeGenerator {
}

public:
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code) {
StubGenerator(CodeBuffer* code, StubGenBlobId blob_id) : StubCodeGenerator(code, blob_id) {
switch(blob_id) {
case initial_id:
generate_initial_stubs();
Expand Down
18 changes: 17 additions & 1 deletion src/hotspot/share/runtime/stubCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ void StubCodeDesc::print() const { print_on(tty); }

StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, bool print_code) {
_masm = new MacroAssembler(code);
_blob_id = StubGenBlobId::NO_BLOBID;
_print_code = PrintStubCode || print_code;
}

StubCodeGenerator::StubCodeGenerator(CodeBuffer* code, StubGenBlobId blob_id, bool print_code) {
_masm = new MacroAssembler(code);
_blob_id = blob_id;
_print_code = PrintStubCode || print_code;
}

Expand Down Expand Up @@ -112,6 +119,11 @@ void StubCodeGenerator::stub_epilog(StubCodeDesc* cdesc) {
}
}

#ifndef PRODUCT
void StubCodeGenerator::verify_stub(StubGenStubId stub_id) {
assert(StubRoutines::stub_to_blob(stub_id) == blob_id(), "wrong blob being used to generate stub");
}
#endif

// Implementation of CodeMark

Expand All @@ -123,7 +135,11 @@ StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, const char* group, const cha
_cdesc->set_begin(_cgen->assembler()->pc());
}

StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, StubGenStubId stub_id) : StubCodeMark(cgen, "StubRoutines", StubRoutines::get_stub_name(stub_id)) { }
StubCodeMark::StubCodeMark(StubCodeGenerator* cgen, StubGenStubId stub_id) : StubCodeMark(cgen, "StubRoutines", StubRoutines::get_stub_name(stub_id)) {
#ifndef PRODUCT
cgen->verify_stub(stub_id);
#endif
}

StubCodeMark::~StubCodeMark() {
_cgen->assembler()->flush();
Expand Down
17 changes: 12 additions & 5 deletions src/hotspot/share/runtime/stubCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,36 @@ class StubCodeDesc: public CHeapObj<mtCode> {
void print() const;
};

// forward declare blob and stub id enums

enum StubGenBlobId : int;
enum StubGenStubId : int;

// The base class for all stub-generating code generators.
// Provides utility functions.

class StubCodeGenerator: public StackObj {
private:
bool _print_code;

StubGenBlobId _blob_id;
protected:
MacroAssembler* _masm;

public:
StubCodeGenerator(CodeBuffer* code, bool print_code = false);
StubCodeGenerator(CodeBuffer* code, StubGenBlobId blob_id, bool print_code = false);
~StubCodeGenerator();

MacroAssembler* assembler() const { return _masm; }
StubGenBlobId blob_id() { return _blob_id; }

virtual void stub_prolog(StubCodeDesc* cdesc); // called by StubCodeMark constructor
virtual void stub_epilog(StubCodeDesc* cdesc); // called by StubCodeMark destructor
};

// forward declare stub id enum

enum StubGenStubId : int;
#ifndef PRODUCT
void verify_stub(StubGenStubId stub_id);
#endif
};

// Stack-allocated helper class used to associate a stub code with a name.
// All stub code generating functions that use a StubCodeMark will be registered
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/runtime/stubRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ bool _verified_stub_ids = verifyStubIds();
// translate a global stub id to an associated blob id based on the
// computed blob limits

StubGenBlobId stub_to_blob(StubGenStubId stubId) {
StubGenBlobId StubRoutines::stub_to_blob(StubGenStubId stubId) {
int id = (int)stubId;
assert(id > ((int)StubGenStubId::NO_STUBID) && id < ((int)StubGenStubId::NUM_STUBIDS), "stub id out of range");
assert(id > ((int)StubGenStubId::NO_STUBID) && id < ((int)StubGenStubId::NUM_STUBIDS), "stub id out of range!");
// start with no blob to catch stub id == -1
StubGenBlobId blobId = StubGenBlobId::NO_BLOBID;
STUBGEN_BLOBS_DO(BLOB_CHECK_OFFSET);
// if we reach here we should have the lats blob id
// if we reach here we should have the last blob id
assert(blobId == StubGenBlobId::NUM_BLOBIDS - 1, "unexpected blob id");
return blobId;
}
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/runtime/stubRoutines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ class StubRoutines: AllStatic {

#undef DEFINE_BLOB_GETTER

#ifndef PRODUCT
// provide a translation from stub id to its associated blob id
static StubGenBlobId stub_to_blob(StubGenStubId stubId);
#endif

// Debugging
static jint verify_oop_count() { return _verify_oop_count; }
static jint* verify_oop_count_addr() { return &_verify_oop_count; }
Expand Down

0 comments on commit d344a67

Please sign in to comment.