src/hotspot/share/compiler/oopMap.cpp
author never
Fri, 25 Oct 2019 13:17:31 -0700
changeset 58805 d3382812b788
parent 58795 3df2bf731a87
permissions -rw-r--r--
8233027: OopMapSet::all_do does oms.next() twice during iteration Reviewed-by: shade, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 52070
diff changeset
     2
 * Copyright (c) 1998, 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: 3795
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
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: 3795
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "code/codeBlob.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "code/codeCache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "code/nmethod.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "code/scopeDesc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "compiler/oopMap.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30590
diff changeset
    31
#include "gc/shared/collectedHeap.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "memory/allocation.inline.hpp"
47676
b1c020fc35a3 8189748: More precise closures for WeakProcessor::weak_oops_do calls
stefank
parents: 47547
diff changeset
    33
#include "memory/iterator.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54780
diff changeset
    35
#include "memory/universe.hpp"
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54623
diff changeset
    36
#include "oops/compressedOops.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/frame.inline.hpp"
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 47799
diff changeset
    38
#include "runtime/handles.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/signature.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    40
#include "utilities/align.hpp"
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
    41
#include "utilities/lockFreeStack.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    42
#ifdef COMPILER1
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    43
#include "c1/c1_Defs.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    44
#endif
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    45
#ifdef COMPILER2
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    46
#include "opto/optoreg.hpp"
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 24424
diff changeset
    47
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// OopMapStream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
    51
OopMapStream::OopMapStream(OopMap* oop_map) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
    52
  _stream = new CompressedReadStream(oop_map->write_stream()->buffer());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _size = oop_map->omv_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _valid_omv = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
    58
OopMapStream::OopMapStream(const ImmutableOopMap* oop_map) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
    59
  _stream = new CompressedReadStream(oop_map->data_addr());
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
    60
  _size = oop_map->count();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _valid_omv = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
void OopMapStream::find_next() {
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
    66
  if (_position++ < _size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    _omv.read_from(_stream);
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
    68
    _valid_omv = true;
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
    69
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _valid_omv = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// OopMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// slots to hold 4-byte values like ints and floats in the LP64 build.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
OopMap::OopMap(int frame_size, int arg_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // OopMaps are usually quite so small, so pick a small initial size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  set_write_stream(new CompressedWriteStream(32));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  set_omv_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  _locs_length = VMRegImpl::stack2reg(0)->value() + frame_size + arg_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  _locs_used   = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
OopMap::OopMap(OopMap::DeepCopyToken, OopMap* source) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // This constructor does a deep copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // of the source OopMap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  set_write_stream(new CompressedWriteStream(source->omv_count() * 2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  set_omv_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  set_offset(source->offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  _locs_length = source->_locs_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // We need to copy the entries too.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  for (OopMapStream oms(source); !oms.is_done(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    OopMapValue omv = oms.current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    omv.write_on(write_stream());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    increment_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
OopMap* OopMap::deep_copy() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return new OopMap(_deep_copy_token, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   118
void OopMap::copy_data_to(address addr) const {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   119
  memcpy(addr, write_stream()->buffer(), write_stream()->position());
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
int OopMap::heap_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  int size = sizeof(OopMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  int align = sizeof(void *) - 1;
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   125
  size += write_stream()->position();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Align to a reasonable ending point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  size = ((size+align) & ~align);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  return size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// slots to hold 4-byte values like ints and floats in the LP64 build.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
void OopMap::set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  assert(reg->value() < _locs_length, "too big reg value for stack size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  assert( _locs_used[reg->value()] == OopMapValue::unused_value, "cannot insert twice" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  debug_only( _locs_used[reg->value()] = x; )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   139
  OopMapValue o(reg, x, optional);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  o.write_on(write_stream());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  increment_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
void OopMap::set_oop(VMReg reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  set_xxx(reg, OopMapValue::oop_value, VMRegImpl::Bad());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   150
void OopMap::set_narrowoop(VMReg reg) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   151
  set_xxx(reg, OopMapValue::narrowoop_value, VMRegImpl::Bad());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
void OopMap::set_callee_saved(VMReg reg, VMReg caller_machine_register ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  set_xxx(reg, OopMapValue::callee_saved_value, caller_machine_register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}
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 OopMap::set_derived_oop(VMReg reg, VMReg derived_from_local_register ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if( reg == derived_from_local_register ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    // Actually an oop, derived shares storage with base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    set_oop(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    set_xxx(reg, OopMapValue::derived_oop_value, derived_from_local_register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// OopMapSet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
OopMapSet::OopMapSet() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  set_om_size(MinOopMapAllocation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  set_om_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  OopMap** temp = NEW_RESOURCE_ARRAY(OopMap*, om_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  set_om_data(temp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
void OopMapSet::grow_om_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  int new_size = om_size() * 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  OopMap** new_data = NEW_RESOURCE_ARRAY(OopMap*, new_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  memcpy(new_data,om_data(),om_size() * sizeof(OopMap*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  set_om_size(new_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  set_om_data(new_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
void OopMapSet::add_gc_map(int pc_offset, OopMap *map ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  assert(om_size() != -1,"Cannot grow a fixed OopMapSet");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if(om_count() >= om_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    grow_om_data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  map->set_offset(pc_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if(om_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    OopMap* last = at(om_count()-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    if (last->offset() == map->offset() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      fatal("OopMap inserted twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if(last->offset() > map->offset()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      tty->print_cr( "WARNING, maps not sorted: pc[%d]=%d, pc[%d]=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
                      om_count(),last->offset(),om_count()+1,map->offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  set(om_count(),map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  increment_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
int OopMapSet::heap_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // The space we use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  int size = sizeof(OopMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  int align = sizeof(void *) - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  size = ((size+align) & ~align);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  size += om_count() * sizeof(OopMap*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Now add in the space needed for the indivdiual OopMaps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  for(int i=0; i < om_count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    size += at(i)->heap_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // We don't need to align this, it will be naturally pointer aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  return size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
OopMap* OopMapSet::singular_oop_map() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  guarantee(om_count() == 1, "Make sure we only have a single gc point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  return at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
OopMap* OopMapSet::find_map_at_offset(int pc_offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  int i, len = om_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  assert( len > 0, "must have pointer maps" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // Scan through oopmaps. Stop when current offset is either equal or greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // than the one we are looking for.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  for( i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    if( at(i)->offset() >= pc_offset )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  assert( i < len, "oopmap not found" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  OopMap* m = at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  assert( m->offset() == pc_offset, "oopmap not found" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  return m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
static void add_derived_oop(oop* base, oop* derived) {
49972
37b2446d7f86 8202552: [AOT][JVMCI] Incorrect usage of INCLUDE_JVMCI and INCLUDE_AOT
kvn
parents: 49393
diff changeset
   254
#if !defined(TIERED) && !INCLUDE_JVMCI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  COMPILER1_PRESENT(ShouldNotReachHere();)
49972
37b2446d7f86 8202552: [AOT][JVMCI] Incorrect usage of INCLUDE_JVMCI and INCLUDE_AOT
kvn
parents: 49393
diff changeset
   256
#endif // !defined(TIERED) && !INCLUDE_JVMCI
47799
1772ebf07d1f 8152470: Add COMPILER2_OR_JVMCI definition
jcm
parents: 47676
diff changeset
   257
#if COMPILER2_OR_JVMCI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  DerivedPointerTable::add(derived, base);
47799
1772ebf07d1f 8152470: Add COMPILER2_OR_JVMCI definition
jcm
parents: 47676
diff changeset
   259
#endif // COMPILER2_OR_JVMCI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // Print oopmap and regmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  tty->print_cr("------ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  CodeBlob* cb = fr->cb();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   268
  const ImmutableOopMapSet* maps = cb->oop_maps();
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   269
  const ImmutableOopMap* map = cb->oop_map_for_return_address(fr->pc());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  map->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if( cb->is_nmethod() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    nmethod* nm = (nmethod*)cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    // native wrappers have no scope data, it is implied
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (nm->is_native_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      tty->print("bci: 0 (native)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      ScopeDesc* scope  = nm->scope_desc_at(fr->pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      tty->print("bci: %d ",scope->bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  fr->print_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  tty->print("     ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  cb->print_value_on(tty);  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  reg_map->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  tty->print_cr("------ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
void OopMapSet::oops_do(const frame *fr, const RegisterMap* reg_map, OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // add derived oops to a table
47676
b1c020fc35a3 8189748: More precise closures for WeakProcessor::weak_oops_do calls
stefank
parents: 47547
diff changeset
   293
  all_do(fr, reg_map, f, add_derived_oop, &do_nothing_cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
void OopMapSet::all_do(const frame *fr, const RegisterMap *reg_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
                       OopClosure* oop_fn, void derived_oop_fn(oop*, oop*),
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   299
                       OopClosure* value_fn) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  CodeBlob* cb = fr->cb();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   301
  assert(cb != NULL, "no codeblob");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  NOT_PRODUCT(if (TraceCodeBlobStacks) trace_codeblob_maps(fr, reg_map);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   305
  const ImmutableOopMapSet* maps = cb->oop_maps();
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   306
  const ImmutableOopMap* map = cb->oop_map_for_return_address(fr->pc());
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   307
  assert(map != NULL, "no ptr map found");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // handle derived pointers first (otherwise base pointer may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // changed before derived pointer offset has been collected)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  {
58795
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   312
    for (OopMapStream oms(map); !oms.is_done(); oms.next()) {
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   313
      OopMapValue omv = oms.current();
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   314
      if (omv.type() != OopMapValue::derived_oop_value) {
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   315
        continue;
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   316
      }
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   317
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
#ifndef TIERED
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      COMPILER1_PRESENT(ShouldNotReachHere();)
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   320
#if INCLUDE_JVMCI
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   321
      if (UseJVMCICompiler) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   322
        ShouldNotReachHere();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   323
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   324
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
#endif // !TIERED
58795
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   326
      oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map);
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   327
      guarantee(loc != NULL, "missing saved register");
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   328
      oop *derived_loc = loc;
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   329
      oop *base_loc    = fr->oopmapreg_to_location(omv.content_reg(), reg_map);
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   330
      // Ignore NULL oops and decoded NULL narrow oops which
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   331
      // equal to CompressedOops::base() when a narrow oop
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   332
      // implicit null check is used in compiled code.
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   333
      // The narrow_oop_base could be NULL or be the address
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   334
      // of the page below heap depending on compressed oops mode.
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   335
      if (base_loc != NULL && *base_loc != NULL && !CompressedOops::is_base(*base_loc)) {
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   336
        derived_oop_fn(base_loc, derived_loc);
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   337
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  {
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   342
    // We want coop and oop oop_types
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   343
    for (OopMapStream oms(map); !oms.is_done(); oms.next()) {
58795
3df2bf731a87 8232083: Minimal VM is broken after JDK-8231586
never
parents: 58527
diff changeset
   344
      OopMapValue omv = oms.current();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map);
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   346
      // It should be an error if no location can be found for a
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   347
      // register mentioned as contained an oop of some kind.  Maybe
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   348
      // this was allowed previously because value_value items might
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   349
      // be missing?
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   350
      guarantee(loc != NULL, "missing saved register");
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   351
      if ( omv.type() == OopMapValue::oop_value ) {
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   352
        oop val = *loc;
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54623
diff changeset
   353
        if (val == NULL || CompressedOops::is_base(val)) {
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   354
          // Ignore NULL oops and decoded NULL narrow oops which
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents: 54623
diff changeset
   355
          // equal to CompressedOops::base() when a narrow oop
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   356
          // implicit null check is used in compiled code.
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   357
          // The narrow_oop_base could be NULL or be the address
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   358
          // of the page below heap depending on compressed oops mode.
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   359
          continue;
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   360
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
#ifdef ASSERT
55310
966a51af2986 8224966: ZGC: Don't skip oop verification in OopMapSet::all_do()
pliden
parents: 54960
diff changeset
   362
        if ((((uintptr_t)loc & (sizeof(*loc)-1)) != 0) ||
966a51af2986 8224966: ZGC: Don't skip oop verification in OopMapSet::all_do()
pliden
parents: 54960
diff changeset
   363
            !Universe::heap()->is_in_or_null(*loc)) {
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   364
          tty->print_cr("# Found non oop pointer.  Dumping state at failure");
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   365
          // try to dump out some helpful debugging information
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   366
          trace_codeblob_maps(fr, reg_map);
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   367
          omv.print();
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   368
          tty->print_cr("register r");
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   369
          omv.reg()->print();
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   370
          tty->print_cr("loc = %p *loc = %p\n", loc, (address)*loc);
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   371
          // do the real assert.
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   372
          assert(Universe::heap()->is_in_or_null(*loc), "found non oop pointer");
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   373
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
#endif // ASSERT
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   375
        oop_fn->do_oop(loc);
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   376
      } else if ( omv.type() == OopMapValue::narrowoop_value ) {
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   377
        narrowOop *nl = (narrowOop*)loc;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   378
#ifndef VM_LITTLE_ENDIAN
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   379
        VMReg vmReg = omv.reg();
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   380
        // Don't do this on SPARC float registers as they can be individually addressed
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   381
        if (!vmReg->is_stack() SPARC_ONLY(&& !vmReg->is_FloatRegister())) {
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   382
          // compressed oops in registers only take up 4 bytes of an
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   383
          // 8 byte register but they are in the wrong part of the
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   384
          // word so adjust loc to point at the right place.
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   385
          nl = (narrowOop*)((address)nl + 4);
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   386
        }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   387
#endif
33063
9e222337a81e 8136406: Remove ZapDeadCompiledLocals code
kvn
parents: 30776
diff changeset
   388
        oop_fn->do_oop(nl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
// Update callee-saved register info for the following frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
void OopMapSet::update_register_map(const frame *fr, RegisterMap *reg_map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  CodeBlob* cb = fr->cb();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  assert(cb != NULL, "no codeblob");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // Any reg might be saved by a safepoint handler (see generate_handler_blob).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  assert( reg_map->_update_for_id == NULL || fr->is_older(reg_map->_update_for_id),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
         "already updated this map; do not 'update' it twice!" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  debug_only(reg_map->_update_for_id = fr->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  // Check if caller must update oop argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  assert((reg_map->include_argument_oops() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
          !cb->caller_must_gc_arguments(reg_map->thread())),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
         "include_argument_oops should already be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  // Scan through oopmap and find location of all callee-saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // (we do not do update in place, since info could be overwritten)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  address pc = fr->pc();
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   415
  const ImmutableOopMap* map  = cb->oop_map_for_return_address(pc);
24320
394d55c783dc 8040919: Uninitialised memory in hotspot/src/share/vm/compiler/oopMap.cpp
morris
parents: 20282
diff changeset
   416
  assert(map != NULL, "no ptr map found");
394d55c783dc 8040919: Uninitialised memory in hotspot/src/share/vm/compiler/oopMap.cpp
morris
parents: 20282
diff changeset
   417
  DEBUG_ONLY(int nof_callee = 0;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   419
  for (OopMapStream oms(map); !oms.is_done(); oms.next()) {
24320
394d55c783dc 8040919: Uninitialised memory in hotspot/src/share/vm/compiler/oopMap.cpp
morris
parents: 20282
diff changeset
   420
    OopMapValue omv = oms.current();
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   421
    if (omv.type() == OopMapValue::callee_saved_value) {
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   422
      VMReg reg = omv.content_reg();
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   423
      oop* loc = fr->oopmapreg_to_location(omv.reg(), reg_map);
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   424
      reg_map->set_location(reg, (address) loc);
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   425
      DEBUG_ONLY(nof_callee++;)
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 58083
diff changeset
   426
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  // Check that runtime stubs save all callee-saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
#ifdef COMPILER2
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   431
  assert(cb->is_compiled_by_c1() || cb->is_compiled_by_jvmci() || !cb->is_runtime_stub() ||
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
         (nof_callee >= SAVED_ON_ENTRY_REG_COUNT || nof_callee >= C_SAVED_ON_ENTRY_REG_COUNT),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
         "must save all");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
#endif // COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   437
// Printing code is present in product build for -XX:+PrintAssembly.
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   438
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   439
static
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   440
void print_register_type(OopMapValue::oop_types x, VMReg optional,
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   441
                         outputStream* st) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  switch( x ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  case OopMapValue::oop_value:
198
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   444
    st->print("Oop");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    break;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 347
diff changeset
   446
  case OopMapValue::narrowoop_value:
15241
87d217c2d183 8005055: pass outputStream to more opto debug routines
kvn
parents: 13963
diff changeset
   447
    st->print("NarrowOop");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  case OopMapValue::callee_saved_value:
15241
87d217c2d183 8005055: pass outputStream to more opto debug routines
kvn
parents: 13963
diff changeset
   450
    st->print("Callers_");
198
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   451
    optional->print_on(st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  case OopMapValue::derived_oop_value:
15241
87d217c2d183 8005055: pass outputStream to more opto debug routines
kvn
parents: 13963
diff changeset
   454
    st->print("Derived_oop_");
198
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   455
    optional->print_on(st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
198
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   462
void OopMapValue::print_on(outputStream* st) const {
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   463
  reg()->print_on(st);
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   464
  st->print("=");
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   465
  print_register_type(type(),content_reg(),st);
8601165a33c3 6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents: 1
diff changeset
   466
  st->print(" ");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   469
void OopMapValue::print() const { print_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   470
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   471
void ImmutableOopMap::print_on(outputStream* st) const {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   472
  OopMapValue omv;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   473
  st->print("ImmutableOopMap {");
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   474
  for(OopMapStream oms(this); !oms.is_done(); oms.next()) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   475
    omv = oms.current();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   476
    omv.print_on(st);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   477
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   478
  st->print("}");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   479
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   481
void ImmutableOopMap::print() const { print_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   482
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
void OopMap::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  OopMapValue omv;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   485
  st->print("OopMap {");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  for(OopMapStream oms((OopMap*)this); !oms.is_done(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    omv = oms.current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    omv.print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   490
  // Print hex offset in addition.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   491
  st->print("off=%d/0x%x}", (int) offset(), (int) offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   494
void OopMap::print() const { print_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   495
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   496
void ImmutableOopMapSet::print_on(outputStream* st) const {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   497
  const ImmutableOopMap* last = NULL;
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   498
  const int len = count();
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   499
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   500
  st->print_cr("ImmutableOopMapSet contains %d OopMaps", len);
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   501
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   502
  for (int i = 0; i < len; i++) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   503
    const ImmutableOopMapPair* pair = pair_at(i);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   504
    const ImmutableOopMap* map = pair->get_from(this);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   505
    if (map != last) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   506
      st->cr();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   507
      map->print_on(st);
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   508
      st->print(" pc offsets: ");
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   509
    }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   510
    last = map;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   511
    st->print("%d ", pair->pc_offset());
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   512
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   513
  st->cr();
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   514
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   516
void ImmutableOopMapSet::print() const { print_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   517
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
void OopMapSet::print_on(outputStream* st) const {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   519
  const int len = om_count();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   521
  st->print_cr("OopMapSet contains %d OopMaps", len);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   523
  for( int i = 0; i < len; i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    OopMap* m = at(i);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   525
    st->print_cr("#%d ",i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    m->print_on(st);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   527
    st->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  }
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   529
  st->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
}
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 198
diff changeset
   531
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   532
void OopMapSet::print() const { print_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   533
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   534
bool OopMap::equals(const OopMap* other) const {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   535
  if (other->_omv_count != _omv_count) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   536
    return false;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   537
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   538
  if (other->write_stream()->position() != write_stream()->position()) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   539
    return false;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   540
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   541
  if (memcmp(other->write_stream()->buffer(), write_stream()->buffer(), write_stream()->position()) != 0) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   542
    return false;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   543
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   544
  return true;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   545
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   546
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   547
const ImmutableOopMap* ImmutableOopMapSet::find_map_at_offset(int pc_offset) const {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   548
  ImmutableOopMapPair* pairs = get_pairs();
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   549
  ImmutableOopMapPair* last  = NULL;
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   550
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   551
  for (int i = 0; i < _count; ++i) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   552
    if (pairs[i].pc_offset() >= pc_offset) {
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   553
      last = &pairs[i];
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   554
      break;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   555
    }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   556
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   557
54960
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   558
  // Heal Coverity issue: potential index out of bounds access.
e46fe26d7f77 8213084: Rework and enhance Print[Opto]Assembly output
lucy
parents: 54916
diff changeset
   559
  guarantee(last != NULL, "last may not be null");
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   560
  assert(last->pc_offset() == pc_offset, "oopmap not found");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   561
  return last->get_from(this);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   562
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   563
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   564
const ImmutableOopMap* ImmutableOopMapPair::get_from(const ImmutableOopMapSet* set) const {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   565
  return set->oopmap_at_offset(_oopmap_offset);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   566
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   567
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   568
ImmutableOopMap::ImmutableOopMap(const OopMap* oopmap) : _count(oopmap->count()) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   569
  address addr = data_addr();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   570
  oopmap->copy_data_to(addr);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   571
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   572
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   573
#ifdef ASSERT
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   574
int ImmutableOopMap::nr_of_bytes() const {
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   575
  OopMapStream oms(this);
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   576
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   577
  while (!oms.is_done()) {
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   578
    oms.next();
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   579
  }
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   580
  return sizeof(ImmutableOopMap) + oms.stream_position();
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   581
}
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   582
#endif
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   583
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   584
ImmutableOopMapBuilder::ImmutableOopMapBuilder(const OopMapSet* set) : _set(set), _empty(NULL), _last(NULL), _empty_offset(-1), _last_offset(-1), _offset(0), _required(-1), _new_set(NULL) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   585
  _mapping = NEW_RESOURCE_ARRAY(Mapping, _set->size());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   586
}
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   587
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   588
int ImmutableOopMapBuilder::size_for(const OopMap* map) const {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   589
  return align_up((int)sizeof(ImmutableOopMap) + map->data_size(), 8);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   590
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   591
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   592
int ImmutableOopMapBuilder::heap_size() {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   593
  int base = sizeof(ImmutableOopMapSet);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   594
  base = align_up(base, 8);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   595
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   596
  // all of ours pc / offset pairs
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   597
  int pairs = _set->size() * sizeof(ImmutableOopMapPair);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   598
  pairs = align_up(pairs, 8);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   599
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   600
  for (int i = 0; i < _set->size(); ++i) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   601
    int size = 0;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   602
    OopMap* map = _set->at(i);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   603
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   604
    if (is_empty(map)) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   605
      /* only keep a single empty map in the set */
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   606
      if (has_empty()) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   607
        _mapping[i].set(Mapping::OOPMAP_EMPTY, _empty_offset, 0, map, _empty);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   608
      } else {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   609
        _empty_offset = _offset;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   610
        _empty = map;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   611
        size = size_for(map);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   612
        _mapping[i].set(Mapping::OOPMAP_NEW, _offset, size, map);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   613
      }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   614
    } else if (is_last_duplicate(map)) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   615
      /* if this entry is identical to the previous one, just point it there */
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   616
      _mapping[i].set(Mapping::OOPMAP_DUPLICATE, _last_offset, 0, map, _last);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   617
    } else {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   618
      /* not empty, not an identical copy of the previous entry */
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   619
      size = size_for(map);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   620
      _mapping[i].set(Mapping::OOPMAP_NEW, _offset, size, map);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   621
      _last_offset = _offset;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   622
      _last = map;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   623
    }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   624
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   625
    assert(_mapping[i]._map == map, "check");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   626
    _offset += size;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   627
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   628
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   629
  int total = base + pairs + _offset;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   630
  DEBUG_ONLY(total += 8);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   631
  _required = total;
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   632
  return total;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   633
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   634
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   635
void ImmutableOopMapBuilder::fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set) {
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   636
  assert(offset < set->nr_of_bytes(), "check");
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   637
  new ((address) pair) ImmutableOopMapPair(map->offset(), offset);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   638
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   639
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   640
int ImmutableOopMapBuilder::fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set) {
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   641
  fill_pair(pair, map, offset, set);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   642
  address addr = (address) pair->get_from(_new_set); // location of the ImmutableOopMap
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   643
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   644
  new (addr) ImmutableOopMap(map);
46618
d503911aa948 8178489: Make align functions more type safe and consistent
stefank
parents: 45327
diff changeset
   645
  return size_for(map);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   646
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   647
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   648
void ImmutableOopMapBuilder::fill(ImmutableOopMapSet* set, int sz) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   649
  ImmutableOopMapPair* pairs = set->get_pairs();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   650
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   651
  for (int i = 0; i < set->count(); ++i) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   652
    const OopMap* map = _mapping[i]._map;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   653
    ImmutableOopMapPair* pair = NULL;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   654
    int size = 0;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   655
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   656
    if (_mapping[i]._kind == Mapping::OOPMAP_NEW) {
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   657
      size = fill_map(&pairs[i], map, _mapping[i]._offset, set);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   658
    } else if (_mapping[i]._kind == Mapping::OOPMAP_DUPLICATE || _mapping[i]._kind == Mapping::OOPMAP_EMPTY) {
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   659
      fill_pair(&pairs[i], map, _mapping[i]._offset, set);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   660
    }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   661
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   662
    const ImmutableOopMap* nv = set->find_map_at_offset(map->offset());
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   663
    assert(memcmp(map->data(), nv->data_addr(), map->data_size()) == 0, "check identity");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   664
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   665
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   666
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   667
#ifdef ASSERT
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   668
void ImmutableOopMapBuilder::verify(address buffer, int size, const ImmutableOopMapSet* set) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   669
  for (int i = 0; i < 8; ++i) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   670
    assert(buffer[size - 8 + i] == (unsigned char) 0xff, "overwritten memory check");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   671
  }
30774
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   672
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   673
  for (int i = 0; i < set->count(); ++i) {
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   674
    const ImmutableOopMapPair* pair = set->pair_at(i);
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   675
    assert(pair->oopmap_offset() < set->nr_of_bytes(), "check size");
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   676
    const ImmutableOopMap* map = pair->get_from(set);
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   677
    int nr_of_bytes = map->nr_of_bytes();
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   678
    assert(pair->oopmap_offset() + nr_of_bytes <= set->nr_of_bytes(), "check size + size");
6745424a720f 8080692: lots of jstack tests failing in pit
rbackman
parents: 30590
diff changeset
   679
  }
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   680
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   681
#endif
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   682
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   683
ImmutableOopMapSet* ImmutableOopMapBuilder::generate_into(address buffer) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   684
  DEBUG_ONLY(memset(&buffer[_required-8], 0xff, 8));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   685
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   686
  _new_set = new (buffer) ImmutableOopMapSet(_set, _required);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   687
  fill(_new_set, _required);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   688
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   689
  DEBUG_ONLY(verify(buffer, _required, _new_set));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   690
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   691
  return _new_set;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   692
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   693
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   694
ImmutableOopMapSet* ImmutableOopMapBuilder::build() {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   695
  _required = heap_size();
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   696
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   697
  // We need to allocate a chunk big enough to hold the ImmutableOopMapSet and all of its ImmutableOopMaps
58083
9046db64ca39 8227168: Cleanup usage of NEW_C_HEAP_ARRAY
lkorinth
parents: 55310
diff changeset
   698
  address buffer = NEW_C_HEAP_ARRAY(unsigned char, _required, mtCode);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33063
diff changeset
   699
  return generate_into(buffer);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   700
}
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   701
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   702
ImmutableOopMapSet* ImmutableOopMapSet::build_from(const OopMapSet* oopmap_set) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   703
  ResourceMark mark;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   704
  ImmutableOopMapBuilder builder(oopmap_set);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   705
  return builder.build();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 25715
diff changeset
   706
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
//------------------------------DerivedPointerTable---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
47799
1772ebf07d1f 8152470: Add COMPILER2_OR_JVMCI definition
jcm
parents: 47676
diff changeset
   711
#if COMPILER2_OR_JVMCI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   713
class DerivedPointerTable::Entry : public CHeapObj<mtCompiler> {
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   714
  oop* _location;   // Location of derived pointer, also pointing to base
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   715
  intptr_t _offset; // Offset from base pointer
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   716
  Entry* volatile _next;
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   717
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   718
  static Entry* volatile* next_ptr(Entry& entry) { return &entry._next; }
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   719
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   720
public:
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   721
  Entry(oop* location, intptr_t offset) :
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   722
    _location(location), _offset(offset), _next(NULL) {}
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   723
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   724
  oop* location() const { return _location; }
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   725
  intptr_t offset() const { return _offset; }
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   726
  Entry* next() const { return _next; }
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   727
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   728
  typedef LockFreeStack<Entry, &next_ptr> List;
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   729
  static List* _list;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   732
DerivedPointerTable::Entry::List* DerivedPointerTable::Entry::_list = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
bool DerivedPointerTable::_active = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   735
bool DerivedPointerTable::is_empty() {
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   736
  return Entry::_list == NULL || Entry::_list->empty();
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   737
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
void DerivedPointerTable::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  // The first time, we create the list.  Otherwise it should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  // empty.  If not, then we have probably forgotton to call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  // update_pointers after last GC/Scavenge.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  assert (!_active, "should not be active");
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   744
  assert(is_empty(), "table not empty");
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   745
  if (Entry::_list == NULL) {
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   746
    void* mem = NEW_C_HEAP_OBJ(Entry::List, mtCompiler);
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   747
    Entry::_list = ::new (mem) Entry::List();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  _active = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
// Returns value of location as an int
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   753
inline intptr_t value_of_loc(oop *pointer) {
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   754
  return cast_from_oop<intptr_t>((*pointer));
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   755
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
void DerivedPointerTable::add(oop *derived_loc, oop *base_loc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  assert(Universe::heap()->is_in_or_null(*base_loc), "not an oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  assert(derived_loc != base_loc, "Base and derived in same location");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  if (_active) {
52070
e4d72440d60e 8211279: Verify missing object equals barriers
rkennke
parents: 51333
diff changeset
   761
    assert(*derived_loc != (void*)base_loc, "location already added");
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   762
    assert(Entry::_list != NULL, "list must exist");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    intptr_t offset = value_of_loc(derived_loc) - value_of_loc(base_loc);
9976
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 7397
diff changeset
   764
    // This assert is invalid because derived pointers can be
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 7397
diff changeset
   765
    // arbitrarily far away from their base.
6fef34e63df1 7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents: 7397
diff changeset
   766
    // assert(offset >= -1000000, "wrong derived pointer info");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    if (TraceDerivedPointers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
      tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
        "Add derived pointer@" INTPTR_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
        " - Derived: " INTPTR_FORMAT
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24320
diff changeset
   772
        " Base: " INTPTR_FORMAT " (@" INTPTR_FORMAT ") (Offset: " INTX_FORMAT ")",
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24320
diff changeset
   773
        p2i(derived_loc), p2i((address)*derived_loc), p2i((address)*base_loc), p2i(base_loc), offset
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    // Set derived oop location to point to base.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    *derived_loc = (oop)base_loc;
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   778
    Entry* entry = new Entry(derived_loc, offset);
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   779
    Entry::_list->push(*entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
void DerivedPointerTable::update_pointers() {
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   784
  assert(Entry::_list != NULL, "list must exist");
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   785
  Entry* entries = Entry::_list->pop_all();
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   786
  while (entries != NULL) {
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   787
    Entry* entry = entries;
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   788
    entries = entry->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    oop* derived_loc = entry->location();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    intptr_t offset  = entry->offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    // The derived oop was setup to point to location of base
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   792
    oop base = **(oop**)derived_loc;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    assert(Universe::heap()->is_in_or_null(base), "must be an oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    *derived_loc = (oop)(((address)base) + offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    assert(value_of_loc(derived_loc) - value_of_loc(&base) == offset, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    if (TraceDerivedPointers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
      tty->print_cr("Updating derived pointer@" INTPTR_FORMAT
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24320
diff changeset
   800
                    " - Derived: " INTPTR_FORMAT "  Base: " INTPTR_FORMAT " (Offset: " INTX_FORMAT ")",
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24320
diff changeset
   801
          p2i(derived_loc), p2i((address)*derived_loc), p2i((address)base), offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    // Delete entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    delete entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  }
54916
7136c9ac56a7 8160539: Stack frame scanning acquires DerivedPointerTableGC_lock mutex
kbarrett
parents: 54807
diff changeset
   807
  assert(Entry::_list->empty(), "invariant");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  _active = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
47799
1772ebf07d1f 8152470: Add COMPILER2_OR_JVMCI definition
jcm
parents: 47676
diff changeset
   811
#endif // COMPILER2_OR_JVMCI