src/hotspot/share/jfr/leakprofiler/utilities/saveRestore.hpp
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 50113 caf115bb98ad
child 53244 9807daeb47c4
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.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
#ifndef SHARE_VM_JFR_LEAKPROFILER_UTILITIES_SAVERESTORE_HPP
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#define SHARE_VM_JFR_LEAKPROFILER_UTILITIES_SAVERESTORE_HPP
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "memory/allocation.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "memory/iterator.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "oops/markOop.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "utilities/growableArray.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
template <typename T, typename Impl>
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
class SaveRestore {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
  Impl _impl;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
  SaveRestore() : _impl() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
    _impl.setup();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
  void save(T const& value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
    _impl.save(value);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
  ~SaveRestore() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
    _impl.restore();
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
template <typename T, typename Context>
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
class ContextStore {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
  GrowableArray<Context>* _storage;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
  ContextStore() : _storage(NULL) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
  void setup() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
    assert(_storage == NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
    _storage = new GrowableArray<Context>(16);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  void save(T const& value) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
    _storage->push(Context(value));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
  void restore() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
    for (int i = 0; i < _storage->length(); ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
      _storage->at(i).~Context();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
};
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
* This class will save the original mark oop of an object sample object.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    76
* It will then install an "identifier" mark oop to be used for
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    77
* identification purposes in the search for reference chains.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
* The destructor will restore the original mark oop.
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
class MarkOopContext {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
  oop _obj;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
  markOop _mark_oop;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
  void swap(MarkOopContext& rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
  MarkOopContext();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
  MarkOopContext(const oop obj);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
  MarkOopContext(const MarkOopContext& rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
  void operator=(MarkOopContext rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
  ~MarkOopContext();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
typedef SaveRestore<oop, ContextStore<oop, MarkOopContext> > SaveRestoreMarkOops;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
class ClassLoaderData;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
class CLDClaimContext {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
  ClassLoaderData* _cld;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
  void swap(CLDClaimContext& rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
  CLDClaimContext();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
  CLDClaimContext(ClassLoaderData* cld);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
  CLDClaimContext(const CLDClaimContext& rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
  void operator=(CLDClaimContext rhs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
  ~CLDClaimContext();
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
typedef SaveRestore<ClassLoaderData*, ContextStore<ClassLoaderData*, CLDClaimContext> > SaveRestoreCLDClaimState;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   112
class CLDClaimStateClosure : public CLDClosure {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
  SaveRestoreCLDClaimState _state;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
  CLDClaimStateClosure();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
  void do_cld(ClassLoaderData* cld);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   120
class SaveRestoreCLDClaimBits : public StackObj {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   121
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   122
  CLDClaimStateClosure _claim_state_closure;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   123
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
  SaveRestoreCLDClaimBits();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   125
  ~SaveRestoreCLDClaimBits();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   126
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   127
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   128
#endif // SHARE_VM_JFR_LEAKPROFILER_UTILITIES_SAVERESTORE_HPP