/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "asm/codeBuffer.hpp"
#include "compiler/disassembler.hpp"
#include "utilities/xmlstream.hpp"
// The structure of a CodeSection:
//
// _start -> +----------------+
// | machine code...|
// _end -> |----------------|
// | |
// | (empty) |
// | |
// | |
// +----------------+
// _limit -> | |
//
// _locs_start -> +----------------+
// |reloc records...|
// |----------------|
// _locs_end -> | |
// | |
// | (empty) |
// | |
// | |
// +----------------+
// _locs_limit -> | |
// The _end (resp. _limit) pointer refers to the first
// unused (resp. unallocated) byte.
// The structure of the CodeBuffer while code is being accumulated:
//
// _total_start -> \
// _insts._start -> +----------------+
// | |
// | Code |
// | |
// _stubs._start -> |----------------|
// | |
// | |
// _consts._start -> |----------------|
// | |
// | Constants |
// | |
// +----------------+
// + _total_size -> | |
//
// When the code and relocations are copied to the code cache,
// the empty parts of each section are removed, and everything
// is copied into contiguous locations.
// External buffer, in a predefined CodeBlob.
// Important: The code_start must be taken exactly, and not realigned.
initialize_misc("static buffer");
}
// Compute maximal alignment.
// Always allow for empty slop around each section.
// The assembler constructor will throw a fatal on an empty CodeBuffer.
return; // caller must test this
}
// Set up various pointers into the blob.
assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned");
if (locs_size != 0) {
}
}
CodeBuffer::~CodeBuffer() {
// If we allocate our code buffer from the CodeCache
// via a BufferBlob, and it's not permanent, then
// free the BufferBlob.
// The rest of the memory will be freed when the ResourceObj
// is released.
// Previous incarnations of this buffer are held live, so that internal
// addresses constructed before expansions will not be confused.
}
// free any overflow storage
delete _overflow_arena;
#ifdef ASSERT
// Save allocation type to execute assert in ~ResourceObj()
// which is called after this destructor.
#endif
}
assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once");
_oop_recorder = r;
}
// give it some relocations to start with, if the main section has them
}
}
// Patch the limits.
// Give remaining buffer space to the following section.
}
}
// Round up the starting address.
} else {
#ifdef ASSERT
// Clean out dangling pointers.
#endif //ASSERT
}
}
}
}
#ifdef PRODUCT
return NULL;
#else //PRODUCT
switch (n) {
case SECT_CONSTS: return "consts";
case SECT_INSTS: return "insts";
case SECT_STUBS: return "stubs";
default: return NULL;
}
#endif //PRODUCT
}
for (int n = 0; n < (int)SECT_LIMIT; n++) {
}
return SECT_NONE;
}
for (int n = 0; n < (int)SECT_LIMIT; n++) {
}
}
return -1;
}
}
return begin;
}
if (_overflow_arena == NULL) {
}
}
// Helper function for managing labels and their target addresses.
// Returns a sensible address, and if it is not the label's final
// address, notes the dependency (at 'branch_pc') on the label.
if (L.is_bound()) {
} else {
}
} else {
// Need to return a pc, doesn't matter what it is since it will be
// replaced during resolution later.
// Don't return NULL or badAddress, since branches shouldn't overflow.
// Don't return base either because that could overflow displacements
// for shorter branches. It will get checked when bound.
return branch_pc;
}
}
// The assertion below has been adjusted, to also work for
// relocation for fixup. Sometimes we want to put relocation
// information for the next instruction, since it will be patched
// with a call.
"cannot relocate data outside code boundaries");
if (!has_locs()) {
// no space for relocation information provided => code cannot be
// relocated. Make sure that relocate is only called with rtypes
// that can be ignored for this kind of code.
"code needs relocation information");
// leave behind an indication that we attempted a relocation
return;
}
// Advance the point, noting the offset we'll have to record.
// Test for a couple of overflow conditions; maybe expand the buffer.
// Check for (potential) overflow
if (req >= locs_limit()) {
// Allocate or reallocate.
// reload pointer
}
}
// If the offset is giant, emit filler relocs, of type 'none', but
// each carrying the largest possible offset, to advance the locs_point.
*end++ = filler_relocInfo();
}
// If it's a simple reloc with no data, we'll just write (rtype | offset).
// If it has data, insert the prefix, as (data_prefix_tag | data1), data2.
}
// Apply a priori lower limits to relocation size:
_locs_own = true;
}
// Internal invariant: locs buf must be fully aligned.
// See copy_relocations_to() below.
}
if (length > 0) {
_locs_start = buf;
_locs_own = false;
}
}
if (lcount != 0) {
}
}
if (_locs_start == NULL) {
return;
} else {
if (_locs_own) {
} else {
_locs_own = true;
}
}
}
/// Support for emitting the code to its final location.
/// The pattern is the same for all functions.
/// We iterate over all the sections, padding each to alignment.
for (int n = 0; n < (int)SECT_LIMIT; n++) {
}
return size_so_far;
}
{
// not sure why this is here, but why not...
}
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
// figure compact layout of each section
// Compute initial padding; assign it to the previous non-empty guy.
// Cf. figure_expanded_capacities.
if (padding != 0) {
buf_offset += padding;
}
#ifdef ASSERT
// Make sure the ends still match up.
// This is important because a branch in a frozen section
// might target code in a following section, via a Label,
// and without a relocation record. See Label::patch_instructions.
}
#endif //ASSERT
}
buf_offset += csize;
}
// Done calculating sections; did it come out to the right end?
}
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
}
return size_so_far;
}
}
return -1;
}
}
}
// if dest == NULL, this is just the sizing pass
for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
// pull relocs out of each section
if (lsize > 0) {
// Figure out how to advance the combined relocation point
// first to the beginning of this section.
// We'll insert one or more filler relocs to span that gap.
// (Don't bother to improve this by editing the first reloc's offset.)
code_point_so_far += jump) {
} else { // else shrink the filler to fit
}
}
buf_offset += sizeof(filler);
}
// Update code point and end to skip past this section:
}
// Done with filler; emit the real relocations:
if (buf_offset % HeapWordSize == 0) {
// Use wordwise copies if possible:
} else {
}
}
buf_offset += lsize;
}
// Align end of relocation info in target.
while (buf_offset % HeapWordSize != 0) {
}
buf_offset += sizeof(relocInfo);
}
// Account for index:
buf_offset / sizeof(relocInfo),
dest->relocation_end());
}
return buf_offset;
}
#ifndef PRODUCT
((CodeBuffer*)this)->print();
}
#endif //PRODUCT
this->compute_final_layout(&dest);
// transfer strings and comments from buffer to blob
// Done moving code bytes; were they the right size?
// Flush generated code
}
// Move all my code into another code buffer. Consult applicable
// relocs to repair embedded addresses. The layout in the destination
// CodeBuffer is different to the source CodeBuffer: the destination
// CodeBuffer gets the final layout (consts, insts, stubs in order of
// ascending address).
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
// pull code out of each section
// Copy the code as aligned machine words.
// This may also include an uninitialized partial word at the end.
wsize / HeapWordSize);
// Destination is a final resting place, not just another buffer.
// Normalize uninitialized bytes in the final padding.
Assembler::code_fill_byte());
}
// Keep track of the highest filled address
"this section carries no reloc storage, but reloc was attempted");
// Make the new code copy use the old copy's relocations:
{ // Repair the pc relative information in the code after the move
}
}
}
// Destination is a final resting place, not just another buffer.
// Normalize uninitialized bytes in the final padding.
Assembler::code_fill_byte());
}
}
csize_t* new_capacity) {
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
// Compute initial padding; assign it to the previous section,
// even if it's empty (e.g. consts section can be empty).
// Cf. compute_final_layout
if (padding != 0) {
new_total_cap += padding;
}
}
} else if (n == SECT_INSTS) {
// scale down inst increases to a more modest 25%
// do not grow an empty secondary section
exp = 0;
}
// Allow for inter-section slop:
// No need to expand after all.
}
new_capacity[n] = new_cap;
new_total_cap += new_cap;
}
return new_total_cap;
}
#ifndef PRODUCT
this->print();
}
static int expand_count = 0;
// simulate an occasional allocation failure:
free_blob();
}
}
#endif //PRODUCT
// Resizing must be allowed
{
for (int n = 0; n < (int)SECT_LIMIT; n++) {
}
}
// Figure new capacity for each section.
// Create a new (temporary) code buffer to hold all the new data
// Failed to allocate in code cache.
free_blob();
return;
}
// Create an old code buffer to remember which addresses used to go where.
// This will be useful when we do final assembly into the code cache,
// because we will need to know how to warp any internal address that
// has been created at any time in this CodeBuffer's past.
this->_before_expand = bxp;
// Give each section its required (expanded) capacity.
if (new_capacity[n] == 0) continue; // already nulled out
if (n != SECT_INSTS) {
}
cb_sect->clear_mark();
} else {
}
}
// Move all the code and relocations to the new blob:
// Copy the temporary code buffer into the current code buffer.
// Basically, do {*this = cb}, except for some control information.
this->take_over_code_from(&cb);
// Zap the old code buffer contents, to avoid mistakenly using them.
// Make certain that the new sections are all snugly inside the new blob.
#ifndef PRODUCT
this->print();
}
#endif //PRODUCT
}
// Must already have disposed of the old blob somehow.
#ifdef ASSERT
#endif
// Take the new blob away from cb.
// Take over all the section pointers.
for (int n = 0; n < (int)SECT_LIMIT; n++) {
}
// Make sure the old cb won't try to use it or free it.
}
}
// Verify disjointness.
for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
"start is aligned");
for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) {
// limit is an exclusive address and can be the start of another
// section.
}
}
}
// log info about buffer usage
}
}
}
#ifndef PRODUCT
while (step > 0) {
}
}
}
}
}
}
private:
friend class CodeStrings;
const char * _string;
~CodeString() {
}
public:
}
if (is_comment()) {
return this;
} else {
return next_comment();
}
}
CodeString* s = _next;
while (s != NULL && !s->is_comment()) {
s = s->_next;
}
return s;
}
};
a = a->next_comment();
}
return a;
}
// Convenience for add_comment.
if (a != NULL) {
CodeString* c = NULL;
a = c;
}
}
return a;
}
if (inspos) {
// insert after already existing comments with same offset
} else {
// no comments with such offset, yet. Insert before anything else.
_strings = c;
}
}
}
c = c->next_comment();
}
}
}
CodeString* n = _strings;
while (n) {
// unlink the node from the list saving a pointer to the next
CodeString* p = n->next();
delete n;
n = p;
}
}
_strings = s;
return s->string();
}
_decode_begin = insts_end();
}
_decode_begin = insts_end();
}
for (int n = 0; n < (int)SECT_LIMIT; n++) {
// dump contents of each section
else
}
}
if (PrintRelocations) {
RelocIterator iter(this);
}
}
if (this == NULL) {
return;
}
for (int n = 0; n < (int)SECT_LIMIT; n++) {
// print each section
}
}
#endif // PRODUCT