Skip to content

Commit 9c5441c

Browse files
committedSep 16, 2021
8271569: Clean up the use of CDS constants and field offsets
Reviewed-by: iklam, dholmes
1 parent 12fa707 commit 9c5441c

File tree

10 files changed

+187
-143
lines changed

10 files changed

+187
-143
lines changed
 
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2014, 2021, 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+
#include "precompiled.hpp"
26+
27+
#include "cds.h"
28+
#include "cds/cdsConstants.hpp"
29+
#include "cds/dynamicArchive.hpp"
30+
#include "cds/filemap.hpp"
31+
#include "utilities/globalDefinitions.hpp"
32+
33+
CDSConst CDSConstants::offsets[] = {
34+
{ "CDSFileMapHeaderBase::_magic", offset_of(CDSFileMapHeaderBase, _magic) },
35+
{ "CDSFileMapHeaderBase::_crc", offset_of(CDSFileMapHeaderBase, _crc) },
36+
{ "CDSFileMapHeaderBase::_version", offset_of(CDSFileMapHeaderBase, _version) },
37+
{ "CDSFileMapHeaderBase::_space[0]", offset_of(CDSFileMapHeaderBase, _space) },
38+
{ "FileMapHeader::_jvm_ident", offset_of(FileMapHeader, _jvm_ident) },
39+
{ "FileMapHeader::_base_archive_name_size", offset_of(FileMapHeader, _base_archive_name_size) },
40+
{ "CDSFileMapRegion::_crc", offset_of(CDSFileMapRegion, _crc) },
41+
{ "CDSFileMapRegion::_used", offset_of(CDSFileMapRegion, _used) },
42+
{ "DynamicArchiveHeader::_base_region_crc", offset_of(DynamicArchiveHeader, _base_region_crc) }
43+
};
44+
45+
CDSConst CDSConstants::constants[] = {
46+
{ "static_magic", (size_t)CDS_ARCHIVE_MAGIC },
47+
{ "dynamic_magic", (size_t)CDS_DYNAMIC_ARCHIVE_MAGIC },
48+
{ "int_size", sizeof(int) },
49+
{ "CDSFileMapRegion_size", sizeof(CDSFileMapRegion) },
50+
{ "static_file_header_size", sizeof(FileMapHeader) },
51+
{ "dynamic_archive_header_size", sizeof(DynamicArchiveHeader) },
52+
{ "size_t_size", sizeof(size_t) }
53+
};
54+
55+
size_t CDSConstants::get_cds_offset(const char* name) {
56+
for (int i = 0; i < (int)ARRAY_SIZE(offsets); i++) {
57+
if (strcmp(name, offsets[i]._name) == 0) {
58+
return offsets[i]._value;
59+
}
60+
}
61+
return -1;
62+
}
63+
64+
size_t CDSConstants::get_cds_constant(const char* name) {
65+
for (int i = 0; i < (int)ARRAY_SIZE(constants); i++) {
66+
if (strcmp(name, constants[i]._name) == 0) {
67+
return constants[i]._value;
68+
}
69+
}
70+
return -1;
71+
}

‎src/hotspot/share/cds/cdsoffsets.hpp ‎src/hotspot/share/cds/cdsConstants.hpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,22 @@
2222
*
2323
*/
2424

25-
#ifndef SHARE_CDS_CDSOFFSETS_HPP
26-
#define SHARE_CDS_CDSOFFSETS_HPP
25+
#ifndef SHARE_CDS_CDSCONSTANTS_HPP
26+
#define SHARE_CDS_CDSCONSTANTS_HPP
2727

28-
#include "memory/allocation.hpp"
28+
#include "memory/allStatic.hpp"
2929

30-
class CDSOffsets: public CHeapObj<mtInternal> {
30+
typedef struct {
31+
const char* _name;
32+
size_t _value;
33+
} CDSConst;
34+
35+
class CDSConstants : AllStatic {
3136
private:
32-
char* _name;
33-
int _offset;
34-
CDSOffsets* _next;
35-
static CDSOffsets* _all; // sole list for cds
37+
static CDSConst offsets[];
38+
static CDSConst constants[];
3639
public:
37-
CDSOffsets(const char* name, int offset, CDSOffsets* next);
38-
39-
char* get_name() const { return _name; }
40-
int get_offset() const { return _offset; }
41-
CDSOffsets* next() const { return _next; }
42-
void add_end(CDSOffsets* n);
43-
44-
static int find_offset(const char* name);
40+
static size_t get_cds_constant(const char* name);
41+
static size_t get_cds_offset(const char* name);
4542
};
46-
47-
#endif // SHARE_CDS_CDSOFFSETS_HPP
43+
#endif // SHARE_CDS_CDSCONSTANTS_HPP

‎src/hotspot/share/cds/cdsoffsets.cpp

-77
This file was deleted.

‎src/hotspot/share/cds/dynamicArchive.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#if INCLUDE_CDS
3939

4040
class DynamicArchiveHeader : public FileMapHeader {
41-
friend class CDSOffsets;
41+
friend class CDSConstants;
4242
private:
4343
int _base_header_crc;
4444
int _base_region_crc[MetaspaceShared::n_regions];

‎src/hotspot/share/cds/filemap.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ class FileMapRegion: private CDSFileMapRegion {
180180
};
181181

182182
class FileMapHeader: private CDSFileMapHeaderBase {
183-
friend class CDSOffsets;
183+
friend class CDSConstants;
184184
friend class VMStructs;
185185

186+
private:
186187
size_t _header_size;
187188

188189
// The following fields record the states of the VM during dump time.
@@ -209,7 +210,6 @@ class FileMapHeader: private CDSFileMapHeaderBase {
209210
// will function correctly with this JVM and the bootclasspath it's
210211
// invoked with.
211212
char _jvm_ident[JVM_IDENT_MAX]; // identifier string of the jvm that created this dump
212-
213213
// size of the base archive name including NULL terminator
214214
size_t _base_archive_name_size;
215215

‎src/hotspot/share/include/cds.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef SHARE_INCLUDE_CDS_H
2626
#define SHARE_INCLUDE_CDS_H
2727

28+
#include <stddef.h>
29+
2830
// This file declares the CDS data structures that are used by the HotSpot Serviceability Agent
2931
// (see C sources inside src/jdk.hotspot.agent).
3032
//

‎src/hotspot/share/prims/whitebox.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "precompiled.hpp"
2626
#include <new>
27-
#include "cds/cdsoffsets.hpp"
27+
#include "cds/cdsConstants.hpp"
2828
#include "cds/filemap.hpp"
2929
#include "cds/heapShared.inline.hpp"
3030
#include "cds/metaspaceShared.hpp"
@@ -2016,11 +2016,18 @@ WB_END
20162016

20172017
#if INCLUDE_CDS
20182018

2019-
WB_ENTRY(jint, WB_GetOffsetForName(JNIEnv* env, jobject o, jstring name))
2019+
WB_ENTRY(jint, WB_GetCDSOffsetForName(JNIEnv* env, jobject o, jstring name))
20202020
ResourceMark rm;
20212021
char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
2022-
int result = CDSOffsets::find_offset(c_name);
2023-
return (jint)result;
2022+
jint result = (jint)CDSConstants::get_cds_offset(c_name);
2023+
return result;
2024+
WB_END
2025+
2026+
WB_ENTRY(jint, WB_GetCDSConstantForName(JNIEnv* env, jobject o, jstring name))
2027+
ResourceMark rm;
2028+
char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
2029+
jint result = (jint)CDSConstants::get_cds_constant(c_name);
2030+
return result;
20242031
WB_END
20252032

20262033
#endif // INCLUDE_CDS
@@ -2454,7 +2461,8 @@ static JNINativeMethod methods[] = {
24542461
{CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea},
24552462
{CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize},
24562463
#if INCLUDE_CDS
2457-
{CC"getOffsetForName0", CC"(Ljava/lang/String;)I", (void*)&WB_GetOffsetForName},
2464+
{CC"getCDSOffsetForName0", CC"(Ljava/lang/String;)I", (void*)&WB_GetCDSOffsetForName},
2465+
{CC"getCDSConstantForName0", CC"(Ljava/lang/String;)I", (void*)&WB_GetCDSConstantForName},
24582466
#endif
24592467
#if INCLUDE_G1GC
24602468
{CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark},

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Sep 16, 2021

@openjdk-notifier[bot]
Please sign in to comment.