src/hotspot/share/jfr/leakprofiler/utilities/saveRestore.cpp
author coleenp
Fri, 28 Sep 2018 16:07:39 -0400
changeset 51959 db0c3952de52
parent 50986 b289815d0db3
child 52141 de6dc206a92b
permissions -rw-r--r--
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files Reviewed-by: iklam, stuefe
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
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
MarkOopContext::MarkOopContext() : _obj(NULL), _mark_oop(NULL) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
MarkOopContext::MarkOopContext(const oop obj) : _obj(obj), _mark_oop(obj->mark()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
  assert(_obj->mark() == _mark_oop, "invariant");
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.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
  assert(NULL == markOopDesc::INFLATING(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
  _obj->set_mark(markOopDesc::INFLATING());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
  assert(NULL == obj->mark(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
MarkOopContext::~MarkOopContext() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
  if (_obj != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
    _obj->set_mark(_mark_oop);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
    assert(_obj->mark() == _mark_oop, "invariant");
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
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
MarkOopContext::MarkOopContext(const MarkOopContext& rhs) : _obj(NULL), _mark_oop(NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
  swap(const_cast<MarkOopContext&>(rhs));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
void MarkOopContext::operator=(MarkOopContext rhs) {
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
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
void MarkOopContext::swap(MarkOopContext& rhs) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
  oop temp_obj = rhs._obj;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
  markOop temp_mark_oop = rhs._mark_oop;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
  rhs._obj = _obj;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  rhs._mark_oop = _mark_oop;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
  _obj = temp_obj;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  _mark_oop = temp_mark_oop;
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");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
  _cld->clear_claimed();
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) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    77
    _cld->claim();
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() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
  ClassLoaderDataGraph::cld_do(&_claim_state_closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
SaveRestoreCLDClaimBits::~SaveRestoreCLDClaimBits() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
  ClassLoaderDataGraph::clear_claimed_marks();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
}