src/hotspot/share/asm/codeBuffer.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58267 acc7ea6bf0b4
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54010
17fb726e6d8e 8219214: Infinite Loop in CodeSection::dump()
lucy
parents: 51078
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    26
#include "asm/codeBuffer.hpp"
54783
3331dad9cb30 8223621: Move Universe usage out of oopRecorder.hpp
stefank
parents: 54010
diff changeset
    27
#include "code/oopRecorder.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    28
#include "compiler/disassembler.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    29
#include "oops/methodData.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    30
#include "oops/oop.inline.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    31
#include "runtime/icache.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 47216
diff changeset
    32
#include "runtime/safepointVerifiers.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    33
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    34
#include "utilities/copy.hpp"
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
    35
#include "utilities/xmlstream.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The structure of a CodeSection:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//    _start ->           +----------------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//                        | machine code...|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//    _end ->             |----------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//                        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//                        |    (empty)     |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//                        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//                        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//                        +----------------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//    _limit ->           |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//    _locs_start ->      +----------------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//                        |reloc records...|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//                        |----------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//    _locs_end ->        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//                        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//                        |    (empty)     |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//                        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//                        |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//                        +----------------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//    _locs_limit ->      |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// The _end (resp. _limit) pointer refers to the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// unused (resp. unallocated) byte.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// The structure of the CodeBuffer while code is being accumulated:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//    _total_start ->    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
//    _insts._start ->              +----------------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
//                                  |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
//                                  |     Code       |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//                                  |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//    _stubs._start ->              |----------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
//                                  |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
//                                  |    Stubs       | (also handlers for deopt/exception)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//                                  |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
//    _consts._start ->             |----------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//                                  |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
//                                  |   Constants    |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//                                  |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
//                                  +----------------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//    + _total_size ->              |                |
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// When the code and relocations are copied to the code cache,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// the empty parts of each section are removed, and everything
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// is copied into contiguous locations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
typedef CodeBuffer::csize_t csize_t;  // file-local definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
    86
// External buffer, in a predefined CodeBlob.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// Important: The code_start must be taken exactly, and not realigned.
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
    88
CodeBuffer::CodeBuffer(CodeBlob* blob) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
    89
  // Provide code buffer with meaningful name
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
    90
  initialize_misc(blob->name());
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
    91
  initialize(blob->content_begin(), blob->content_size());
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
    92
  verify_section_allocation();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Compute maximal alignment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  int align = _insts.alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Always allow for empty slop around each section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  int slop = (int) CodeSection::end_slop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  assert(blob() == NULL, "only once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  if (blob() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // The assembler constructor will throw a fatal on an empty CodeBuffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    return;  // caller must test this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Set up various pointers into the blob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  initialize(_total_start, _total_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   111
  assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  pd_initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  if (locs_size != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    _insts.initialize_locs(locs_size / sizeof(relocInfo));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   119
  verify_section_allocation();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
CodeBuffer::~CodeBuffer() {
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   124
  verify_section_allocation();
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   125
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // If we allocate our code buffer from the CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // via a BufferBlob, and it's not permanent, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // free the BufferBlob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // The rest of the memory will be freed when the ResourceObj
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // is released.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // Previous incarnations of this buffer are held live, so that internal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // addresses constructed before expansions will not be confused.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    cb->free_blob();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
2025
a13c4b3f024e 6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents: 670
diff changeset
   136
a13c4b3f024e 6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents: 670
diff changeset
   137
  // free any overflow storage
a13c4b3f024e 6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents: 670
diff changeset
   138
  delete _overflow_arena;
a13c4b3f024e 6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents: 670
diff changeset
   139
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
   140
  // Claim is that stack allocation ensures resources are cleaned up.
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
   141
  // This is resource clean up, let's hope that all were properly copied out.
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
   142
  free_strings();
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
   143
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#ifdef ASSERT
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5883
diff changeset
   145
  // Save allocation type to execute assert in ~ResourceObj()
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5883
diff changeset
   146
  // which is called after this destructor.
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   147
  assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object");
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5883
diff changeset
   148
  ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  Copy::fill_to_bytes(this, sizeof(*this), badResourceValue);
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5883
diff changeset
   150
  ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
void CodeBuffer::initialize_oop_recorder(OopRecorder* r) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   156
  DEBUG_ONLY(_default_oop_recorder.freeze());  // force unused OR to be frozen
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  _oop_recorder = r;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  assert(cs != &_insts, "insts is the memory provider, not the consumer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  csize_t slop = CodeSection::end_slop();  // margin between sections
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  int align = cs->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  assert(is_power_of_2(align), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  address start  = _insts._start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  address limit  = _insts._limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  address middle = limit - size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  middle -= (intptr_t)middle & (align-1);  // align the division point downward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  guarantee(middle - slop > start, "need enough space to divide up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  _insts._limit = middle - slop;  // subtract desired space, plus slop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  cs->initialize(middle, limit - middle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(cs->start() == middle, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  assert(cs->limit() == limit,  "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // give it some relocations to start with, if the main section has them
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  if (_insts.has_locs())  cs->initialize_locs(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
void CodeBuffer::freeze_section(CodeSection* cs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  CodeSection* next_cs = (cs == consts())? NULL: code_section(cs->index()+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  csize_t frozen_size = cs->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  if (next_cs != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    frozen_size = next_cs->align_at_start(frozen_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  address old_limit = cs->limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  address new_limit = cs->start() + frozen_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  relocInfo* old_locs_limit = cs->locs_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  relocInfo* new_locs_limit = cs->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Patch the limits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  cs->_limit = new_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  cs->_locs_limit = new_locs_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  cs->_frozen = true;
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   192
  if (next_cs != NULL && !next_cs->is_allocated() && !next_cs->is_frozen()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // Give remaining buffer space to the following section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    next_cs->initialize(new_limit, old_limit - new_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    next_cs->initialize_shared_locs(new_locs_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                                    old_locs_limit - new_locs_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
void CodeBuffer::set_blob(BufferBlob* blob) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  _blob = blob;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  if (blob != NULL) {
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   203
    address start = blob->content_begin();
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   204
    address end   = blob->content_end();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // Round up the starting address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    int align = _insts.alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    start += (-(intptr_t)start) & (align-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    _total_start = start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    _total_size  = end - start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  } else {
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   211
#ifdef ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    // Clean out dangling pointers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    _total_start    = badAddress;
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   214
    _consts._start  = _consts._end  = badAddress;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    _insts._start   = _insts._end   = badAddress;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    _stubs._start   = _stubs._end   = badAddress;
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   217
#endif //ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
void CodeBuffer::free_blob() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (_blob != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    BufferBlob::free(_blob);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    set_blob(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
const char* CodeBuffer::code_section_name(int n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
#ifdef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
#else //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  switch (n) {
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   233
  case SECT_CONSTS:            return "consts";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  case SECT_INSTS:             return "insts";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  case SECT_STUBS:             return "stubs";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  default:                     return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
int CodeBuffer::section_index_of(address addr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    const CodeSection* cs = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    if (cs->allocates(addr))  return n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  return SECT_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
int CodeBuffer::locator(address addr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    const CodeSection* cs = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    if (cs->allocates(addr)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      return locator(addr - cs->start(), n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
address CodeBuffer::locator_address(int locator) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  if (locator < 0)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  address start = code_section(locator_sect(locator))->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  return start + locator_pos(locator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14624
diff changeset
   265
bool CodeBuffer::is_backward_branch(Label& L) {
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14624
diff changeset
   266
  return L.is_bound() && insts_end() <= locator_address(L.loc());
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14624
diff changeset
   267
}
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14624
diff changeset
   268
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
address CodeBuffer::decode_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  address begin = _insts.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (_decode_begin != NULL && _decode_begin > begin)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    begin = _decode_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  return begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
GrowableArray<int>* CodeBuffer::create_patch_overflow() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  if (_overflow_arena == NULL) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 25715
diff changeset
   279
    _overflow_arena = new (mtCode) Arena(mtCode);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
// Helper function for managing labels and their target addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
// Returns a sensible address, and if it is not the label's final
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
// address, notes the dependency (at 'branch_pc') on the label.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
address CodeSection::target(Label& L, address branch_pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if (L.is_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    int loc = L.loc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    if (index() == CodeBuffer::locator_sect(loc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      return start() + CodeBuffer::locator_pos(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      return outer()->locator_address(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    assert(allocates2(branch_pc), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    address base = start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    int patch_loc = CodeBuffer::locator(branch_pc - base, index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    L.add_patch_at(outer(), patch_loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    // Need to return a pc, doesn't matter what it is since it will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    // replaced during resolution later.
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   304
    // Don't return NULL or badAddress, since branches shouldn't overflow.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   305
    // Don't return base either because that could overflow displacements
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   306
    // for shorter branches.  It will get checked when bound.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   307
    return branch_pc;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   311
void CodeSection::relocate(address at, relocInfo::relocType rtype, int format, jint method_index) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   312
  RelocationHolder rh;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   313
  switch (rtype) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   314
    case relocInfo::none: return;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   315
    case relocInfo::opt_virtual_call_type: {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   316
      rh = opt_virtual_call_Relocation::spec(method_index);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   317
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   318
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   319
    case relocInfo::static_call_type: {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   320
      rh = static_call_Relocation::spec(method_index);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   321
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   322
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   323
    case relocInfo::virtual_call_type: {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   324
      assert(method_index == 0, "resolved method overriding is not supported");
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   325
      rh = Relocation::spec_simple(rtype);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   326
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   327
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   328
    default: {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   329
      rh = Relocation::spec_simple(rtype);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   330
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   331
    }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   332
  }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   333
  relocate(at, rh, format);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   334
}
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 33794
diff changeset
   335
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
void CodeSection::relocate(address at, RelocationHolder const& spec, int format) {
41685
7df85c88cdc0 8166562: C2: Suppress relocations in scratch emit.
goetz
parents: 38133
diff changeset
   337
  // Do not relocate in scratch buffers.
7df85c88cdc0 8166562: C2: Suppress relocations in scratch emit.
goetz
parents: 38133
diff changeset
   338
  if (scratch_emit()) { return; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  Relocation* reloc = spec.reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  relocInfo::relocType rtype = (relocInfo::relocType) reloc->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  if (rtype == relocInfo::none)  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // The assertion below has been adjusted, to also work for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // relocation for fixup.  Sometimes we want to put relocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  // information for the next instruction, since it will be patched
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  // with a call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  assert(start() <= at && at <= end()+1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
         "cannot relocate data outside code boundaries");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  if (!has_locs()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    // no space for relocation information provided => code cannot be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    // relocated.  Make sure that relocate is only called with rtypes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    // that can be ignored for this kind of code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    assert(rtype == relocInfo::none              ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
           rtype == relocInfo::runtime_call_type ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
           rtype == relocInfo::internal_word_type||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
           rtype == relocInfo::section_word_type ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
           rtype == relocInfo::external_word_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
           "code needs relocation information");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    // leave behind an indication that we attempted a relocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    DEBUG_ONLY(_locs_start = _locs_limit = (relocInfo*)badAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  // Advance the point, noting the offset we'll have to record.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  csize_t offset = at - locs_point();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  set_locs_point(at);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  // Test for a couple of overflow conditions; maybe expand the buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  relocInfo* end = locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  relocInfo* req = end + relocInfo::length_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // Check for (potential) overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  if (req >= locs_limit() || offset >= relocInfo::offset_limit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    req += (uint)offset / (uint)relocInfo::offset_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    if (req >= locs_limit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      // Allocate or reallocate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      expand_locs(locs_count() + (req - end));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      // reload pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      end = locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  // If the offset is giant, emit filler relocs, of type 'none', but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // each carrying the largest possible offset, to advance the locs_point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  while (offset >= relocInfo::offset_limit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    assert(end < locs_limit(), "adjust previous paragraph of code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    *end++ = filler_relocInfo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    offset -= filler_relocInfo().addr_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // If it's a simple reloc with no data, we'll just write (rtype | offset).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  (*end) = relocInfo(rtype, offset, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  // If it has data, insert the prefix, as (data_prefix_tag | data1), data2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  end->initialize(this, reloc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
void CodeSection::initialize_locs(int locs_capacity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  assert(_locs_start == NULL, "only one locs init step, please");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // Apply a priori lower limits to relocation size:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  csize_t min_locs = MAX2(size() / 16, (csize_t)4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  if (locs_capacity < min_locs)  locs_capacity = min_locs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  relocInfo* locs_start = NEW_RESOURCE_ARRAY(relocInfo, locs_capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  _locs_start    = locs_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  _locs_end      = locs_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  _locs_limit    = locs_start + locs_capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  _locs_own      = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
void CodeSection::initialize_shared_locs(relocInfo* buf, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  assert(_locs_start == NULL, "do this before locs are allocated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // Internal invariant:  locs buf must be fully aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // See copy_relocations_to() below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  while ((uintptr_t)buf % HeapWordSize != 0 && length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    ++buf; --length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  if (length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    _locs_start = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    _locs_end   = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    _locs_limit = buf + length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    _locs_own   = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
void CodeSection::initialize_locs_from(const CodeSection* source_cs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  int lcount = source_cs->locs_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  if (lcount != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    initialize_shared_locs(source_cs->locs_start(), lcount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    _locs_end = _locs_limit = _locs_start + lcount;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    assert(is_allocated(), "must have copied code already");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    set_locs_point(start() + source_cs->locs_point_off());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  assert(this->locs_count() == source_cs->locs_count(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
void CodeSection::expand_locs(int new_capacity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  if (_locs_start == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    initialize_locs(new_capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    int old_count    = locs_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    int old_capacity = locs_capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    if (new_capacity < old_capacity * 2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
      new_capacity = old_capacity * 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    relocInfo* locs_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    if (_locs_own) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity);
5883
8dc4bdc132d5 6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents: 5547
diff changeset
   450
      Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      _locs_own = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    _locs_start    = locs_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    _locs_end      = locs_start + old_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    _locs_limit    = locs_start + new_capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
/// Support for emitting the code to its final location.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
/// The pattern is the same for all functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
/// We iterate over all the sections, padding each to alignment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   464
csize_t CodeBuffer::total_content_size() const {
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   465
  csize_t size_so_far = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    const CodeSection* cs = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    if (cs->is_empty())  continue;  // skip trivial section
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   469
    size_so_far = cs->align_at_start(size_so_far);
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   470
    size_so_far += cs->size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   472
  return size_so_far;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
void CodeBuffer::compute_final_layout(CodeBuffer* dest) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  address buf = dest->_total_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  csize_t buf_offset = 0;
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   478
  assert(dest->_total_size >= total_content_size(), "must be big enough");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    // not sure why this is here, but why not...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  const CodeSection* prev_cs      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  CodeSection*       prev_dest_cs = NULL;
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   488
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   489
  for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    // figure compact layout of each section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    const CodeSection* cs = code_section(n);
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   492
    csize_t csize = cs->size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    CodeSection* dest_cs = dest->code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    if (!cs->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
      // Compute initial padding; assign it to the previous non-empty guy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
      // Cf. figure_expanded_capacities.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      csize_t padding = cs->align_at_start(buf_offset) - buf_offset;
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   499
      if (prev_dest_cs != NULL) {
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   500
        if (padding != 0) {
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   501
          buf_offset += padding;
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   502
          prev_dest_cs->_limit += padding;
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   503
        }
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   504
      } else {
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 49594
diff changeset
   505
        guarantee(padding == 0, "In first iteration no padding should be needed.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      #ifdef ASSERT
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   508
      if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
        // Make sure the ends still match up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
        // This is important because a branch in a frozen section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
        // might target code in a following section, via a Label,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
        // and without a relocation record.  See Label::patch_instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        address dest_start = buf+buf_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
        csize_t start2start = cs->start() - prev_cs->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
        csize_t dest_start2start = dest_start - prev_dest_cs->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
        assert(start2start == dest_start2start, "cannot stretch frozen sect");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      #endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      prev_dest_cs = dest_cs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      prev_cs      = cs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    debug_only(dest_cs->_start = NULL);  // defeat double-initialization assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    dest_cs->initialize(buf+buf_offset, csize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    dest_cs->set_end(buf+buf_offset+csize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    assert(dest_cs->is_allocated(), "must always be allocated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    assert(cs->is_empty() == dest_cs->is_empty(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    buf_offset += csize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  // Done calculating sections; did it come out to the right end?
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   533
  assert(buf_offset == total_content_size(), "sanity");
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   534
  dest->verify_section_allocation();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
14816
f2935b95cb54 8004883: NPG: clean up anonymous class fix
coleenp
parents: 14633
diff changeset
   537
// Append an oop reference that keeps the class alive.
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   538
static void append_oop_references(GrowableArray<oop>* oops, Klass* k) {
14816
f2935b95cb54 8004883: NPG: clean up anonymous class fix
coleenp
parents: 14633
diff changeset
   539
  oop cl = k->klass_holder();
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   540
  if (cl != NULL && !oops->contains(cl)) {
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   541
    oops->append(cl);
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   542
  }
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   543
}
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   544
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33160
diff changeset
   545
void CodeBuffer::finalize_oop_references(const methodHandle& mh) {
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 33794
diff changeset
   546
  NoSafepointVerifier nsv;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   547
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   548
  GrowableArray<oop> oops;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   549
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   550
  // Make sure that immediate metadata records something in the OopRecorder
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   551
  for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   552
    // pull code out of each section
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   553
    CodeSection* cs = code_section(n);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   554
    if (cs->is_empty())  continue;  // skip trivial section
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   555
    RelocIterator iter(cs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   556
    while (iter.next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   557
      if (iter.type() == relocInfo::metadata_type) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   558
        metadata_Relocation* md = iter.metadata_reloc();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   559
        if (md->metadata_is_immediate()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   560
          Metadata* m = md->metadata_value();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   561
          if (oop_recorder()->is_real(m)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   562
            if (m->is_methodData()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   563
              m = ((MethodData*)m)->method();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   564
            }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   565
            if (m->is_method()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   566
              m = ((Method*)m)->method_holder();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   567
            }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   568
            if (m->is_klass()) {
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   569
              append_oop_references(&oops, (Klass*)m);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   570
            } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   571
              // XXX This will currently occur for MDO which don't
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   572
              // have a backpointer.  This has to be fixed later.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   573
              m->print();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   574
              ShouldNotReachHere();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   575
            }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   576
          }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   577
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   578
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   579
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   580
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   581
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   582
  if (!oop_recorder()->is_unused()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   583
    for (int i = 0; i < oop_recorder()->metadata_count(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   584
      Metadata* m = oop_recorder()->metadata_at(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   585
      if (oop_recorder()->is_real(m)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   586
        if (m->is_methodData()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   587
          m = ((MethodData*)m)->method();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   588
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   589
        if (m->is_method()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   590
          m = ((Method*)m)->method_holder();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   591
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   592
        if (m->is_klass()) {
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   593
          append_oop_references(&oops, (Klass*)m);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   594
        } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   595
          m->print();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   596
          ShouldNotReachHere();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   597
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   598
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   599
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   600
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   601
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   602
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   603
  // Add the class loader of Method* for the nmethod itself
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14294
diff changeset
   604
  append_oop_references(&oops, mh->method_holder());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   605
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   606
  // Add any oops that we've found
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   607
  Thread* thread = Thread::current();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   608
  for (int i = 0; i < oops.length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   609
    oop_recorder()->find_index((jobject)thread->handle_area()->allocate_handle(oops.at(i)));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   610
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   611
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   612
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   613
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   614
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 35495
diff changeset
   615
csize_t CodeBuffer::total_offset_of(const CodeSection* cs) const {
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   616
  csize_t size_so_far = 0;
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   617
  for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   618
    const CodeSection* cur_cs = code_section(n);
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   619
    if (!cur_cs->is_empty()) {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   620
      size_so_far = cur_cs->align_at_start(size_so_far);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    }
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   622
    if (cur_cs->index() == cs->index()) {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   623
      return size_so_far;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    }
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   625
    size_so_far += cur_cs->size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
csize_t CodeBuffer::total_relocation_size() const {
46469
f0f38f5ac34f 8180423: Remove flag UseRelocIndex
redestad
parents: 42064
diff changeset
   632
  csize_t total = copy_relocations_to(NULL);  // dry run only
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46469
diff changeset
   633
  return (csize_t) align_up(total, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   636
csize_t CodeBuffer::copy_relocations_to(address buf, csize_t buf_limit, bool only_inst) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  csize_t buf_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  csize_t code_end_so_far = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  csize_t code_point_so_far = 0;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   640
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   641
  assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   642
  assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   643
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   644
  for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   645
    if (only_inst && (n != (int)SECT_INSTS)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   646
      // Need only relocation info for code.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   647
      continue;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   648
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    // pull relocs out of each section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    const CodeSection* cs = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    if (cs->is_empty())  continue;  // skip trivial section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    relocInfo* lstart = cs->locs_start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    relocInfo* lend   = cs->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    csize_t    lsize  = (csize_t)( (address)lend - (address)lstart );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    csize_t    csize  = cs->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    code_end_so_far = cs->align_at_start(code_end_so_far);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    if (lsize > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      // Figure out how to advance the combined relocation point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      // first to the beginning of this section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
      // We'll insert one or more filler relocs to span that gap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
      // (Don't bother to improve this by editing the first reloc's offset.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
      csize_t new_code_point = code_end_so_far;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      for (csize_t jump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
           code_point_so_far < new_code_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
           code_point_so_far += jump) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
        jump = new_code_point - code_point_so_far;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
        relocInfo filler = filler_relocInfo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
        if (jump >= filler.addr_offset()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
          jump = filler.addr_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
        } else {  // else shrink the filler to fit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
          filler = relocInfo(relocInfo::none, jump);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
        if (buf != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
          assert(buf_offset + (csize_t)sizeof(filler) <= buf_limit, "filler in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
          *(relocInfo*)(buf+buf_offset) = filler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
        buf_offset += sizeof(filler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
      // Update code point and end to skip past this section:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
      csize_t last_code_point = code_end_so_far + cs->locs_point_off();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      assert(code_point_so_far <= last_code_point, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      code_point_so_far = last_code_point; // advance past this guy's relocs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    code_end_so_far += csize;  // advance past this guy's instructions too
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    // Done with filler; emit the real relocations:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    if (buf != NULL && lsize != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
      assert(buf_offset + lsize <= buf_limit, "target in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      assert((uintptr_t)lstart % HeapWordSize == 0, "sane start");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
      if (buf_offset % HeapWordSize == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
        // Use wordwise copies if possible:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        Copy::disjoint_words((HeapWord*)lstart,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
                             (HeapWord*)(buf+buf_offset),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
                             (lsize + HeapWordSize-1) / HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
      } else {
5883
8dc4bdc132d5 6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents: 5547
diff changeset
   699
        Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    buf_offset += lsize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  // Align end of relocation info in target.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  while (buf_offset % HeapWordSize != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    if (buf != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      relocInfo padding = relocInfo(relocInfo::none, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
      assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
      *(relocInfo*)(buf+buf_offset) = padding;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
    buf_offset += sizeof(relocInfo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   715
  assert(only_inst || code_end_so_far == total_content_size(), "sanity");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   716
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   717
  return buf_offset;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   718
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   719
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   720
csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   721
  address buf = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   722
  csize_t buf_offset = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   723
  csize_t buf_limit = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   724
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   725
  if (dest != NULL) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   726
    buf = (address)dest->relocation_begin();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   727
    buf_limit = (address)dest->relocation_end() - buf;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   728
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   729
  // if dest == NULL, this is just the sizing pass
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   730
  //
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
   731
  buf_offset = copy_relocations_to(buf, buf_limit, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  return buf_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
void CodeBuffer::copy_code_to(CodeBlob* dest_blob) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  if (PrintNMethods && (WizardMode || Verbose)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    tty->print("done with CodeBuffer:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
    ((CodeBuffer*)this)->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   744
  CodeBuffer dest(dest_blob);
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   745
  assert(dest_blob->content_size() >= total_content_size(), "good sizing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  this->compute_final_layout(&dest);
42064
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   747
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   748
  // Set beginning of constant table before relocating.
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   749
  dest_blob->set_ctable_begin(dest.consts()->start());
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   750
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  relocate_code_to(&dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
   753
  // transfer strings and comments from buffer to blob
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
   754
  dest_blob->set_strings(_code_strings);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  // Done moving code bytes; were they the right size?
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   757
  assert((int)align_up(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  // Flush generated code
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
   760
  ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   763
// Move all my code into another code buffer.  Consult applicable
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   764
// relocs to repair embedded addresses.  The layout in the destination
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   765
// CodeBuffer is different to the source CodeBuffer: the destination
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   766
// CodeBuffer gets the final layout (consts, insts, stubs in order of
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   767
// ascending address).
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
void CodeBuffer::relocate_code_to(CodeBuffer* dest) const {
10964
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   769
  address dest_end = dest->_total_start + dest->_total_size;
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   770
  address dest_filled = NULL;
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   771
  for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    // pull code out of each section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    const CodeSection* cs = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    if (cs->is_empty())  continue;  // skip trivial section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    CodeSection* dest_cs = dest->code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    assert(cs->size() == dest_cs->size(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    csize_t usize = dest_cs->size();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46469
diff changeset
   778
    csize_t wsize = align_up(usize, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    assert(dest_cs->start() + wsize <= dest_end, "no overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    // Copy the code as aligned machine words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    // This may also include an uninitialized partial word at the end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    Copy::disjoint_words((HeapWord*)cs->start(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
                         (HeapWord*)dest_cs->start(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
                         wsize / HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    if (dest->blob() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      // Destination is a final resting place, not just another buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      // Normalize uninitialized bytes in the final padding.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
                          Assembler::code_fill_byte());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    }
10964
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   792
    // Keep track of the highest filled address
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   793
    dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    assert(cs->locs_start() != (relocInfo*)badAddress,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
           "this section carries no reloc storage, but reloc was attempted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    // Make the new code copy use the old copy's relocations:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    dest_cs->initialize_locs_from(cs);
14624
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   800
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
14624
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   802
  // Do relocation after all sections are copied.
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   803
  // This is necessary if the code uses constants in stubs, which are
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   804
  // relocated when the corresponding instruction in the code (e.g., a
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   805
  // call) is relocated. Stubs are placed behind the main code
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   806
  // section, so that section has to be copied before relocating.
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   807
  for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) {
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   808
    // pull code out of each section
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   809
    const CodeSection* cs = code_section(n);
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   810
    if (cs->is_empty()) continue;  // skip trivial section
8f5ec8cfe196 8003850: add support for constants in stub code
kvn
parents: 14294
diff changeset
   811
    CodeSection* dest_cs = dest->code_section(n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    { // Repair the pc relative information in the code after the move
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
      RelocIterator iter(dest_cs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
        iter.reloc()->fix_relocation_after_move(this, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  }
10964
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   819
14294
130e947dfbe6 8000780: make Zero build and run with JDK8
twisti
parents: 13887
diff changeset
   820
  if (dest->blob() == NULL && dest_filled != NULL) {
10964
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   821
    // Destination is a final resting place, not just another buffer.
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   822
    // Normalize uninitialized bytes in the final padding.
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   823
    Copy::fill_to_bytes(dest_filled, dest_end - dest_filled,
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   824
                        Assembler::code_fill_byte());
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   825
97771fdc4ad2 7103380: assertion failure with -XX:+PrintNativeNMethods
never
parents: 7440
diff changeset
   826
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
                                               csize_t amount,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
                                               csize_t* new_capacity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  csize_t new_total_cap = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   834
  for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    const CodeSection* sect = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    if (!sect->is_empty()) {
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   838
      // Compute initial padding; assign it to the previous section,
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   839
      // even if it's empty (e.g. consts section can be empty).
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   840
      // Cf. compute_final_layout
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
      csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      if (padding != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
        new_total_cap += padding;
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   844
        assert(n - 1 >= SECT_FIRST, "sanity");
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   845
        new_capacity[n - 1] += padding;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    csize_t exp = sect->size();  // 100% increase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    if ((uint)exp < 4*K)  exp = 4*K;       // minimum initial increase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    if (sect == which_cs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
      if (exp < amount)  exp = amount;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
      if (StressCodeBuffers)  exp = amount;  // expand only slightly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    } else if (n == SECT_INSTS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      // scale down inst increases to a more modest 25%
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
      exp = 4*K + ((exp - 4*K) >> 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
      if (StressCodeBuffers)  exp = amount / 2;  // expand only slightly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    } else if (sect->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      // do not grow an empty secondary section
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
      exp = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    // Allow for inter-section slop:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    exp += CodeSection::end_slop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    csize_t new_cap = sect->size() + exp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    if (new_cap < sect->capacity()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      // No need to expand after all.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
      new_cap = sect->capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    new_capacity[n] = new_cap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    new_total_cap += new_cap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  return new_total_cap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  if (PrintNMethods && (WizardMode || Verbose)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    tty->print("expanding CodeBuffer:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    this->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  if (StressCodeBuffers && blob() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    static int expand_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
    if (expand_count >= 0)  expand_count += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    if (expand_count > 100 && is_power_of_2(expand_count)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
      tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
      // simulate an occasional allocation failure:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
      free_blob();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  // Resizing must be allowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    if (blob() == NULL)  return;  // caller must check for blob == NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      guarantee(!code_section(n)->is_frozen(), "resizing not allowed when frozen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  // Figure new capacity for each section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  csize_t new_capacity[SECT_LIMIT];
33794
41ef3dc95179 8140482: Various minor code improvements (runtime)
goetz
parents: 33593
diff changeset
   904
  memset(new_capacity, 0, sizeof(csize_t) * SECT_LIMIT);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  csize_t new_total_cap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    = figure_expanded_capacities(which_cs, amount, new_capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  // Create a new (temporary) code buffer to hold all the new data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  CodeBuffer cb(name(), new_total_cap, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  if (cb.blob() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    // Failed to allocate in code cache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    free_blob();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  // Create an old code buffer to remember which addresses used to go where.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  // This will be useful when we do final assembly into the code cache,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  // because we will need to know how to warp any internal address that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  // has been created at any time in this CodeBuffer's past.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  CodeBuffer* bxp = new CodeBuffer(_total_start, _total_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  bxp->take_over_code_from(this);  // remember the old undersized blob
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  DEBUG_ONLY(this->_blob = NULL);  // silence a later assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  bxp->_before_expand = this->_before_expand;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  this->_before_expand = bxp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  // Give each section its required (expanded) capacity.
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   927
  for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    CodeSection* cb_sect   = cb.code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    CodeSection* this_sect = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    if (new_capacity[n] == 0)  continue;  // already nulled out
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   931
    if (n != SECT_INSTS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      cb.initialize_section_size(cb_sect, new_capacity[n]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
    assert(cb_sect->capacity() >= new_capacity[n], "big enough");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    address cb_start = cb_sect->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    cb_sect->set_end(cb_start + this_sect->size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    if (this_sect->mark() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
      cb_sect->clear_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
      cb_sect->set_mark(cb_start + this_sect->mark_off());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
42064
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   944
  // Needs to be initialized when calling fix_relocation_after_move.
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   945
  cb.blob()->set_ctable_begin(cb.consts()->start());
a530dbabe64f 8167184: [s390] Extend relocations for pc-relative instructions.
goetz
parents: 41685
diff changeset
   946
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  // Move all the code and relocations to the new blob:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  relocate_code_to(&cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  // Copy the temporary code buffer into the current code buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  // Basically, do {*this = cb}, except for some control information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  this->take_over_code_from(&cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  cb.set_blob(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  // Zap the old code buffer contents, to avoid mistakenly using them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
                                 badCodeHeapFreeVal));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  _decode_begin = NULL;  // sanity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  // Make certain that the new sections are all snugly inside the new blob.
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   962
  verify_section_allocation();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  if (PrintNMethods && (WizardMode || Verbose)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    tty->print("expanded CodeBuffer:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
    this->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
#endif //PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
void CodeBuffer::take_over_code_from(CodeBuffer* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  // Must already have disposed of the old blob somehow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  assert(blob() == NULL, "must be empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  // Take the new blob away from cb.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  set_blob(cb->blob());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  // Take over all the section pointers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    CodeSection* cb_sect   = cb->code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    CodeSection* this_sect = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    this_sect->take_over_code_from(cb_sect);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  _overflow_arena = cb->_overflow_arena;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  // Make sure the old cb won't try to use it or free it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   988
void CodeBuffer::verify_section_allocation() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  address tstart = _total_start;
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   990
  if (tstart == badAddress)  return;  // smashed by set_blob(NULL)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  address tend   = tstart + _total_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  if (_blob != NULL) {
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   993
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   994
    guarantee(tstart >= _blob->content_begin(), "sanity");
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
   995
    guarantee(tend   <= _blob->content_end(),   "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  }
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   997
  // Verify disjointness.
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   998
  for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    CodeSection* sect = code_section(n);
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1000
    if (!sect->is_allocated() || sect->is_empty())  continue;
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1001
    guarantee((intptr_t)sect->start() % sect->alignment() == 0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
           || sect->is_empty() || _blob == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
           "start is aligned");
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1004
    for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1005
      CodeSection* other = code_section(m);
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1006
      if (!other->is_allocated() || other == sect)  continue;
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1007
      guarantee(!other->contains(sect->start()    ), "sanity");
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1008
      // limit is an exclusive address and can be the start of another
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1009
      // section.
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1010
      guarantee(!other->contains(sect->limit() - 1), "sanity");
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
  1011
    }
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1012
    guarantee(sect->end() <= tend, "sanity");
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1013
    guarantee(sect->end() <= sect->limit(), "sanity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
}
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1016
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1017
void CodeBuffer::log_section_sizes(const char* name) {
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1018
  if (xtty != NULL) {
24002
4e6a72032a99 8005079: fix LogCompilation for incremental inlining
roland
parents: 22234
diff changeset
  1019
    ttyLocker ttyl;
10983
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1020
    // log info about buffer usage
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1021
    xtty->print_cr("<blob name='%s' size='%d'>", name, _total_size);
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1022
    for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1023
      CodeSection* sect = code_section(n);
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1024
      if (!sect->is_allocated() || sect->is_empty())  continue;
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1025
      xtty->print_cr("<sect index='%d' size='" SIZE_FORMAT "' free='" SIZE_FORMAT "'/>",
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1026
                     n, sect->limit() - sect->start(), sect->limit() - sect->end());
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1027
    }
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1028
    xtty->print_cr("</blob>");
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1029
  }
9ab65f4cec18 7104960: JSR 292: +VerifyMethodHandles in product JVM can overflow buffer
never
parents: 10964
diff changeset
  1030
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
void CodeSection::decode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  Disassembler::decode(start(), end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
void CodeBuffer::block_comment(intptr_t offset, const char * comment) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1039
  if (_collect_comments) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1040
    _code_strings.add_comment(offset, comment);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1041
  }
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1042
}
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1043
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1044
const char* CodeBuffer::code_string(const char* str) {
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1045
  return _code_strings.add_string(str);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1048
class CodeString: public CHeapObj<mtCode> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
 private:
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1050
  friend class CodeStrings;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1051
  const char * _string;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1052
  CodeString*  _next;
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1053
  CodeString*  _prev;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  intptr_t     _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1056
  ~CodeString() {
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1057
    assert(_next == NULL && _prev == NULL, "wrong interface for freeing list");
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26432
diff changeset
  1058
    os::free((void*)_string);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1061
  bool is_comment() const { return _offset >= 0; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1063
 public:
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1064
  CodeString(const char * string, intptr_t offset = -1)
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1065
    : _next(NULL), _prev(NULL), _offset(offset) {
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1066
    _string = os::strdup(string, mtCode);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  }
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1068
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1069
  const char * string() const { return _string; }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1070
  intptr_t     offset() const { assert(_offset >= 0, "offset for non comment?"); return _offset;  }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1071
  CodeString* next()    const { return _next; }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1072
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1073
  void set_next(CodeString* next) {
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1074
    _next = next;
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1075
    if (next != NULL) {
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1076
      next->_prev = this;
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1077
    }
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1078
  }
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1079
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1080
  CodeString* first_comment() {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1081
    if (is_comment()) {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1082
      return this;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1083
    } else {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1084
      return next_comment();
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1085
    }
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1086
  }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1087
  CodeString* next_comment() const {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1088
    CodeString* s = _next;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1089
    while (s != NULL && !s->is_comment()) {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1090
      s = s->_next;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1091
    }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1092
    return s;
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1093
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1096
CodeString* CodeStrings::find(intptr_t offset) const {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1097
  CodeString* a = _strings->first_comment();
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1098
  while (a != NULL && a->offset() != offset) {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1099
    a = a->next_comment();
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1100
  }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1101
  return a;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1102
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1104
// Convenience for add_comment.
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1105
CodeString* CodeStrings::find_last(intptr_t offset) const {
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1106
  CodeString* a = _strings_last;
58267
acc7ea6bf0b4 8231058: VerifyOops crashes with assert(_offset >= 0) failed: offset for non comment?
thartmann
parents: 57834
diff changeset
  1107
  while (a != NULL && !(a->is_comment() && a->offset() == offset)) {
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1108
    a = a->_prev;
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1109
  }
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1110
  return a;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1111
}
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1112
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1113
void CodeStrings::add_comment(intptr_t offset, const char * comment) {
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1114
  check_valid();
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1115
  CodeString* c      = new CodeString(comment, offset);
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1116
  CodeString* inspos = (_strings == NULL) ? NULL : find_last(offset);
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1117
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1118
  if (inspos) {
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1119
    // insert after already existing comments with same offset
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1120
    c->set_next(inspos->next());
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1121
    inspos->set_next(c);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  } else {
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1123
    // no comments with such offset, yet. Insert before anything else.
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1124
    c->set_next(_strings);
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1125
    _strings = c;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  }
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1127
  if (c->next() == NULL) {
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1128
    _strings_last = c;
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1129
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1132
void CodeStrings::assign(CodeStrings& other) {
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1133
  other.check_valid();
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1134
  assert(is_null(), "Cannot assign onto non-empty CodeStrings");
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1135
  _strings = other._strings;
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1136
  _strings_last = other._strings_last;
31599
f1b42743d3ee 8081406: cleanup and minor extensions of the debugging facilities in CodeStrings
bdelsart
parents: 30764
diff changeset
  1137
#ifdef ASSERT
f1b42743d3ee 8081406: cleanup and minor extensions of the debugging facilities in CodeStrings
bdelsart
parents: 30764
diff changeset
  1138
  _defunct = false;
f1b42743d3ee 8081406: cleanup and minor extensions of the debugging facilities in CodeStrings
bdelsart
parents: 30764
diff changeset
  1139
#endif
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1140
  other.set_null_and_invalidate();
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1141
}
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1142
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1143
// Deep copy of CodeStrings for consistent memory management.
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1144
// Only used for actual disassembly so this is cheaper than reference counting
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1145
// for the "normal" fastdebug case.
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1146
void CodeStrings::copy(CodeStrings& other) {
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1147
  other.check_valid();
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1148
  check_valid();
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1149
  assert(is_null(), "Cannot copy onto non-empty CodeStrings");
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1150
  CodeString* n = other._strings;
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1151
  CodeString** ps = &_strings;
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1152
  CodeString* prev = NULL;
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1153
  while (n != NULL) {
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1154
    *ps = new CodeString(n->string(),n->offset());
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1155
    (*ps)->_prev = prev;
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1156
    prev = *ps;
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1157
    ps = &((*ps)->_next);
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1158
    n = n->next();
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1159
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
31599
f1b42743d3ee 8081406: cleanup and minor extensions of the debugging facilities in CodeStrings
bdelsart
parents: 30764
diff changeset
  1162
const char* CodeStrings::_prefix = " ;; ";  // default: can be changed via set_prefix
f1b42743d3ee 8081406: cleanup and minor extensions of the debugging facilities in CodeStrings
bdelsart
parents: 30764
diff changeset
  1163
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1164
// Check if any block comments are pending for the given offset.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1165
bool CodeStrings::has_block_comment(intptr_t offset) const {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1166
  if (_strings == NULL) return false;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1167
  CodeString* c = find(offset);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1168
  return c != NULL;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1169
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1170
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1171
void CodeStrings::print_block_comment(outputStream* stream, intptr_t offset) const {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1172
  check_valid();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1173
  if (_strings != NULL) {
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1174
    CodeString* c = find(offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
    while (c && c->offset() == offset) {
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
  1176
      stream->bol();
31599
f1b42743d3ee 8081406: cleanup and minor extensions of the debugging facilities in CodeStrings
bdelsart
parents: 30764
diff changeset
  1177
      stream->print("%s", _prefix);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31599
diff changeset
  1178
      // Don't interpret as format strings since it could contain %
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1179
      stream->print_raw(c->string());
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1180
      stream->bol(); // advance to next line only if string didn't contain a cr() at the end.
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1181
      c = c->next_comment();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1186
// Also sets isNull()
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1187
void CodeStrings::free() {
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1188
  CodeString* n = _strings;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  while (n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    // unlink the node from the list saving a pointer to the next
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1191
    CodeString* p = n->next();
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1192
    n->set_next(NULL);
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1193
    if (p != NULL) {
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1194
      assert(p->_prev == n, "missing prev link");
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1195
      p->_prev = NULL;
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1196
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    delete n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    n = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  }
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1200
  set_null_and_invalidate();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1203
const char* CodeStrings::add_string(const char * string) {
26432
9b974e2eae27 8054292: code comments leak in fastdebug builds
drchase
parents: 25946
diff changeset
  1204
  check_valid();
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1205
  CodeString* s = new CodeString(string);
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1206
  s->set_next(_strings);
57834
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1207
  if (_strings == NULL) {
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1208
    _strings_last = s;
e686b661fa05 8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
thartmann
parents: 54960
diff changeset
  1209
  }
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1210
  _strings = s;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1211
  assert(s->string() != NULL, "should have a string");
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1212
  return s->string();
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 14816
diff changeset
  1213
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
void CodeBuffer::decode() {
13887
89b873bcc55b 7200163: add CodeComments functionality to assember stubs
kvn
parents: 13728
diff changeset
  1216
  ttyLocker ttyl;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1217
  Disassembler::decode(decode_begin(), insts_end(), tty);
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6180
diff changeset
  1218
  _decode_begin = insts_end();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
void CodeSection::print(const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
  csize_t locs_size = locs_end() - locs_start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
  tty->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)%s",
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24002
diff changeset
  1224
                name, p2i(start()), p2i(end()), p2i(limit()), size(), capacity(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
                is_frozen()? " [frozen]": "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
  tty->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d",
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24002
diff changeset
  1227
                name, p2i(locs_start()), p2i(locs_end()), p2i(locs_limit()), locs_size, locs_capacity(), locs_point_off());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  if (PrintRelocations) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    RelocIterator iter(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    iter.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
void CodeBuffer::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
  if (this == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    tty->print_cr("NULL CodeBuffer pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  tty->print_cr("CodeBuffer:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    // print each section
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    CodeSection* cs = code_section(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    cs->print(code_section_name(n));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1248
// Directly disassemble code buffer.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1249
void CodeBuffer::decode(address start, address end) {
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1250
  ttyLocker ttyl;
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1251
  Disassembler::decode(this, start, end, tty);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1252
}
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54783
diff changeset
  1253
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
#endif // PRODUCT