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