Skip to content

Commit 20020d1

Browse files
committed
8254360: Re-examine use of CodeBuffer::verify_section_allocation
Reviewed-by: neliasso, thartmann, kvn
1 parent e56a8df commit 20020d1

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/hotspot/share/asm/codeBuffer.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -90,7 +90,7 @@ CodeBuffer::CodeBuffer(CodeBlob* blob) {
9090
// Provide code buffer with meaningful name
9191
initialize_misc(blob->name());
9292
initialize(blob->content_begin(), blob->content_size());
93-
verify_section_allocation();
93+
debug_only(verify_section_allocation();)
9494
}
9595

9696
void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
@@ -117,7 +117,7 @@ void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
117117
_insts.initialize_locs(locs_size / sizeof(relocInfo));
118118
}
119119

120-
verify_section_allocation();
120+
debug_only(verify_section_allocation();)
121121
}
122122

123123

@@ -494,7 +494,7 @@ void CodeBuffer::compute_final_layout(CodeBuffer* dest) const {
494494

495495
// Done calculating sections; did it come out to the right end?
496496
assert(buf_offset == total_content_size(), "sanity");
497-
dest->verify_section_allocation();
497+
debug_only(dest->verify_section_allocation();)
498498
}
499499

500500
// Append an oop reference that keeps the class alive.
@@ -914,10 +914,10 @@ void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) {
914914

915915
// Zap the old code buffer contents, to avoid mistakenly using them.
916916
debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
917-
badCodeHeapFreeVal));
917+
badCodeHeapFreeVal);)
918918

919919
// Make certain that the new sections are all snugly inside the new blob.
920-
verify_section_allocation();
920+
debug_only(verify_section_allocation();)
921921

922922
#ifndef PRODUCT
923923
_decode_begin = NULL; // sanity
@@ -949,24 +949,23 @@ void CodeBuffer::verify_section_allocation() {
949949
if (tstart == badAddress) return; // smashed by set_blob(NULL)
950950
address tend = tstart + _total_size;
951951
if (_blob != NULL) {
952-
953952
guarantee(tstart >= _blob->content_begin(), "sanity");
954953
guarantee(tend <= _blob->content_end(), "sanity");
955954
}
956955
// Verify disjointness.
957956
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
958957
CodeSection* sect = code_section(n);
959-
if (!sect->is_allocated() || sect->is_empty()) continue;
960-
guarantee((intptr_t)sect->start() % sect->alignment() == 0
961-
|| sect->is_empty() || _blob == NULL,
958+
if (!sect->is_allocated() || sect->is_empty()) {
959+
continue;
960+
}
961+
guarantee(_blob == nullptr || is_aligned(sect->start(), sect->alignment()),
962962
"start is aligned");
963-
for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) {
963+
for (int m = n + 1; m < (int) SECT_LIMIT; m++) {
964964
CodeSection* other = code_section(m);
965-
if (!other->is_allocated() || other == sect) continue;
966-
guarantee(!other->contains(sect->start() ), "sanity");
967-
// limit is an exclusive address and can be the start of another
968-
// section.
969-
guarantee(!other->contains(sect->limit() - 1), "sanity");
965+
if (!other->is_allocated() || other == sect) {
966+
continue;
967+
}
968+
guarantee(other->disjoint(sect), "sanity");
970969
}
971970
guarantee(sect->end() <= tend, "sanity");
972971
guarantee(sect->end() <= sect->limit(), "sanity");

src/hotspot/share/asm/codeBuffer.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -177,6 +177,12 @@ class CodeSection {
177177
bool allocates(address pc) const { return pc >= _start && pc < _limit; }
178178
bool allocates2(address pc) const { return pc >= _start && pc <= _limit; }
179179

180+
// checks if two CodeSections are disjoint
181+
//
182+
// limit is an exclusive address and can be the start of another
183+
// section.
184+
bool disjoint(CodeSection* cs) const { return cs->_limit <= _start || cs->_start >= _limit; }
185+
180186
void set_end(address pc) { assert(allocates2(pc), "not in CodeBuffer memory: " INTPTR_FORMAT " <= " INTPTR_FORMAT " <= " INTPTR_FORMAT, p2i(_start), p2i(pc), p2i(_limit)); _end = pc; }
181187
void set_mark(address pc) { assert(contains2(pc), "not in codeBuffer");
182188
_mark = pc; }
@@ -485,7 +491,7 @@ class CodeBuffer: public StackObj {
485491
assert(code_start != NULL, "sanity");
486492
initialize_misc("static buffer");
487493
initialize(code_start, code_size);
488-
verify_section_allocation();
494+
debug_only(verify_section_allocation();)
489495
}
490496

491497
// (2) CodeBuffer referring to pre-allocated CodeBlob.

0 commit comments

Comments
 (0)