src/hotspot/share/jfr/leakprofiler/utilities/saveRestore.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 57777 90ead0febf56
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 50986
diff changeset
    26
#include "classfile/classLoaderDataGraph.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "jfr/leakprofiler/utilities/saveRestore.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "oops/oop.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    30
MarkWordContext::MarkWordContext() : _obj(NULL), _mark_word(markWord::zero()) {}
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    32
MarkWordContext::MarkWordContext(const oop obj) : _obj(obj), _mark_word(obj->mark()) {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    33
  assert(_obj->mark() == _mark_word, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
  // now we will "poison" the mark word of the object
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
  // to the intermediate monitor INFLATING state.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
  // This is an "impossible" state during a safepoint,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
  // hence we will use it to quickly identify objects
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
  // during the reachability search from gc roots.
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    39
  assert(markWord::zero() == markWord::INFLATING(), "invariant");
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    40
  _obj->set_mark(markWord::INFLATING());
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    41
  assert(markWord::zero() == obj->mark(), "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    44
MarkWordContext::~MarkWordContext() {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
  if (_obj != NULL) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    46
    _obj->set_mark(_mark_word);
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    47
    assert(_obj->mark() == _mark_word, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    51
MarkWordContext::MarkWordContext(const MarkWordContext& rhs) : _obj(NULL), _mark_word(markWord::zero()) {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    52
  swap(const_cast<MarkWordContext&>(rhs));
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    55
void MarkWordContext::operator=(MarkWordContext rhs) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
  swap(rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    59
void MarkWordContext::swap(MarkWordContext& rhs) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
  oop temp_obj = rhs._obj;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    61
  markWord temp_mark_word = rhs._mark_word;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
  rhs._obj = _obj;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    63
  rhs._mark_word = _mark_word;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
  _obj = temp_obj;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 52586
diff changeset
    65
  _mark_word = temp_mark_word;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
CLDClaimContext::CLDClaimContext() : _cld(NULL) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
CLDClaimContext::CLDClaimContext(ClassLoaderData* cld) : _cld(cld) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
  assert(_cld->claimed(), "invariant");
52141
de6dc206a92b 8210330: Make CLD claiming allow multiple claim bits
eosterlund
parents: 51959
diff changeset
    72
  _cld->clear_claim();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    73
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    74
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    75
CLDClaimContext::~CLDClaimContext() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    76
  if (_cld != NULL) {
52141
de6dc206a92b 8210330: Make CLD claiming allow multiple claim bits
eosterlund
parents: 51959
diff changeset
    77
    _cld->try_claim(ClassLoaderData::_claim_strong);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
    assert(_cld->claimed(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
CLDClaimContext::CLDClaimContext(const CLDClaimContext& rhs) : _cld(NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
  swap(const_cast<CLDClaimContext&>(rhs));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
void CLDClaimContext::operator=(CLDClaimContext rhs) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
  swap(rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
void CLDClaimContext::swap(CLDClaimContext& rhs) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
  ClassLoaderData* temp_cld = rhs._cld;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
  rhs._cld = _cld;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
  _cld = temp_cld;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
CLDClaimStateClosure::CLDClaimStateClosure() : CLDClosure(), _state() {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
void CLDClaimStateClosure::do_cld(ClassLoaderData* cld) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
  assert(cld != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
  if (cld->claimed()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
    _state.save(cld);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
SaveRestoreCLDClaimBits::SaveRestoreCLDClaimBits() : _claim_state_closure() {
52586
74109912c738 8213751: ClassLoaderDataGraph::cld_do() should sometimes require CLDG_lock
coleenp
parents: 52141
diff changeset
   106
  // interferes with GC, so walk all oops that GC would.
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
  ClassLoaderDataGraph::cld_do(&_claim_state_closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
SaveRestoreCLDClaimBits::~SaveRestoreCLDClaimBits() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
  ClassLoaderDataGraph::clear_claimed_marks();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   112
}