src/hotspot/share/memory/dynamicArchive.hpp
author ccheung
Fri, 17 May 2019 08:29:55 -0700
changeset 54927 1512d88b24c6
child 58096 0d97bf7cf8a4
permissions -rw-r--r--
8207812: Implement Dynamic CDS Archive Summary: Improve the usability of AppCDS Reviewed-by: acorn, jiangli, mseledtsov Contributed-by: ioi.lam@oracle.com, jianglizhou@google.com, calvin.cheung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     1
/*
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     4
 *
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     8
 *
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    13
 * accompanied this code).
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    14
 *
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    18
 *
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    21
 * questions.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    22
 *
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    23
 */
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    24
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    25
#ifndef SHARE_VM_MEMORY_DYNAMICARCHIVE_HPP
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    26
#define SHARE_VM_MEMORY_DYNAMICARCHIVE_HPP
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    27
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    28
#if INCLUDE_CDS
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    29
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    30
#include "classfile/compactHashtable.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    31
#include "memory/allocation.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    32
#include "memory/filemap.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    33
#include "memory/memRegion.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    34
#include "memory/virtualspace.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    35
#include "oops/oop.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    36
#include "utilities/exceptions.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    37
#include "utilities/macros.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    38
#include "utilities/resourceHash.hpp"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    39
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    40
// We want to include all archive header information in the dynamic archive.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    41
// This helps simplify the process if the base layer archive is missing at
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    42
// dynamic archiving time.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    43
struct DynamicArchiveHeader : public FileMapHeader {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    44
  // crc for the base archive header and regions
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    45
  int _base_archive_crc[MetaspaceShared::n_regions+1];
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    46
};
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    47
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    48
class DynamicArchive : AllStatic {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    49
  static class DynamicArchiveBuilder* _builder;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    50
  static address original_to_target_impl(address orig_obj);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    51
  static address original_to_buffer_impl(address orig_obj);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    52
  static address buffer_to_target_impl(address buff_obj);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    53
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    54
public:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    55
  static void dump();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    56
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    57
  // obj is a copy of a MetaspaceObj, stored in the dumping buffer.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    58
  //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    59
  // The return value is the runtime targeted location of this object as
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    60
  // mapped from the dynamic archive.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    61
  template <typename T> static T buffer_to_target(T buff_obj) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    62
    return (T)buffer_to_target_impl(address(buff_obj));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    63
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    64
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    65
  // obj is an original MetaspaceObj used by the JVM (e.g., a valid Symbol* in the
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    66
  // SymbolTable).
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    67
  //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    68
  // The return value is the runtime targeted location of this object as
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    69
  // mapped from the dynamic archive.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    70
  template <typename T> static T original_to_target(T obj) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    71
    return (T)original_to_target_impl(address(obj));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    72
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    73
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    74
  // obj is an original MetaspaceObj use by the JVM (e.g., a valid Symbol* in the
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    75
  // SymbolTable).
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    76
  //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    77
  // The return value is the location of this object in the dump time
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    78
  // buffer space
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    79
  template <typename T> static T original_to_buffer(T obj) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    80
    return (T)original_to_buffer_impl(address(obj));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    81
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    82
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    83
  // Delta of this object from SharedBaseAddress
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    84
  static uintx object_delta_uintx(void* buff_obj);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    85
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    86
  // Does obj point to an address inside the runtime target space of the dynamic
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    87
  // archive?
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    88
  static bool is_in_target_space(void *obj);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    89
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    90
  static address map();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    91
  static bool is_mapped();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    92
  static bool validate(FileMapInfo* dynamic_info);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    93
  static void disable();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    94
private:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    95
  static address map_impl(FileMapInfo* mapinfo);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    96
  static void map_failed(FileMapInfo* mapinfo);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    97
};
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    98
#endif // INCLUDE_CDS
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents:
diff changeset
    99
#endif // SHARE_VM_MEMORY_DYNAMICARCHIVE_HPP