Skip to content

Commit 3e70aac

Browse files
committed
8254162: Implementation of Foreign-Memory Access API (Third Incubator)
Reviewed-by: erikj, psandoz, alanb
1 parent c6ab0fd commit 3e70aac

File tree

82 files changed

+6011
-2810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+6011
-2810
lines changed

make/modules/java.base/Gensrc.gmk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ include gensrc/GensrcExceptions.gmk
3535
include gensrc/GensrcVarHandles.gmk
3636
include gensrc/GensrcModuleLoaderMap.gmk
3737
include gensrc/GensrcEmojiData.gmk
38+
include gensrc/GensrcScopedMemoryAccess.gmk
3839

3940
# GensrcLocaleData.gmk does not set TARGETS, so we must choose which targets
4041
# to include.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#
2+
# Copyright (c) 2020, 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. Oracle designates this
8+
# particular file as subject to the "Classpath" exception as provided
9+
# by Oracle in the LICENSE file that accompanied this code.
10+
#
11+
# This code is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
# version 2 for more details (a copy is included in the LICENSE file that
15+
# accompanied this code).
16+
#
17+
# You should have received a copy of the GNU General Public License version
18+
# 2 along with this work; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
#
21+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
# or visit www.oracle.com if you need additional information or have any
23+
# questions.
24+
#
25+
26+
SCOPED_MEMORY_ACCESS_GENSRC_DIR := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/jdk/internal/misc
27+
SCOPED_MEMORY_ACCESS_SRC_DIR := $(TOPDIR)/src/java.base/share/classes/jdk/internal/misc
28+
SCOPED_MEMORY_ACCESS_TEMPLATE := $(SCOPED_MEMORY_ACCESS_SRC_DIR)/X-ScopedMemoryAccess.java.template
29+
SCOPED_MEMORY_ACCESS_BIN_TEMPLATE := $(SCOPED_MEMORY_ACCESS_SRC_DIR)/X-ScopedMemoryAccess-bin.java.template
30+
SCOPED_MEMORY_ACCESS_DEST := $(SCOPED_MEMORY_ACCESS_GENSRC_DIR)/ScopedMemoryAccess.java
31+
32+
################################################################################
33+
# Setup a rule for generating the ScopedMemoryAccess java class
34+
# Param 1 - Variable declaration prefix
35+
# Param 2 - Type with first letter capitalized
36+
define GenerateScopedOp
37+
38+
$1_Type := $2
39+
40+
ifeq ($$($1_Type), Byte)
41+
$1_type := byte
42+
$1_BoxType := $$($1_Type)
43+
44+
$1_rawType := $$($1_type)
45+
$1_RawType := $$($1_Type)
46+
$1_RawBoxType := $$($1_BoxType)
47+
48+
$1_ARGS += -Kbyte
49+
endif
50+
51+
ifeq ($$($1_Type), Short)
52+
$1_type := short
53+
$1_BoxType := $$($1_Type)
54+
55+
$1_rawType := $$($1_type)
56+
$1_RawType := $$($1_Type)
57+
$1_RawBoxType := $$($1_BoxType)
58+
$1_ARGS += -KUnaligned
59+
endif
60+
61+
ifeq ($$($1_Type), Char)
62+
$1_type := char
63+
$1_BoxType := Character
64+
65+
$1_rawType := $$($1_type)
66+
$1_RawType := $$($1_Type)
67+
$1_RawBoxType := $$($1_BoxType)
68+
$1_ARGS += -KUnaligned
69+
endif
70+
71+
ifeq ($$($1_Type), Int)
72+
$1_type := int
73+
$1_BoxType := Integer
74+
75+
$1_rawType := $$($1_type)
76+
$1_RawType := $$($1_Type)
77+
$1_RawBoxType := $$($1_BoxType)
78+
79+
$1_ARGS += -KCAS
80+
$1_ARGS += -KAtomicAdd
81+
$1_ARGS += -KBitwise
82+
$1_ARGS += -KUnaligned
83+
endif
84+
85+
ifeq ($$($1_Type), Long)
86+
$1_type := long
87+
$1_BoxType := $$($1_Type)
88+
89+
$1_rawType := $$($1_type)
90+
$1_RawType := $$($1_Type)
91+
$1_RawBoxType := $$($1_BoxType)
92+
93+
$1_ARGS += -KCAS
94+
$1_ARGS += -KAtomicAdd
95+
$1_ARGS += -KBitwise
96+
$1_ARGS += -KUnaligned
97+
endif
98+
99+
ifeq ($$($1_Type), Float)
100+
$1_type := float
101+
$1_BoxType := $$($1_Type)
102+
103+
$1_rawType := int
104+
$1_RawType := Int
105+
$1_RawBoxType := Integer
106+
107+
$1_ARGS += -KCAS
108+
$1_ARGS += -KfloatingPoint
109+
endif
110+
111+
ifeq ($$($1_Type), Double)
112+
$1_type := double
113+
$1_BoxType := $$($1_Type)
114+
115+
$1_rawType := long
116+
$1_RawType := Long
117+
$1_RawBoxType := Long
118+
119+
$1_ARGS += -KCAS
120+
$1_ARGS += -KfloatingPoint
121+
endif
122+
123+
ifneq ($$(findstring $$($1_Type), Byte Short Char Int Long Float Double), )
124+
$1_ARGS += -KAtomicAdd
125+
endif
126+
127+
ifneq ($$(findstring $$($1_Type), Boolean Byte Short Char Int Long), )
128+
$1_ARGS += -KBitwise
129+
endif
130+
131+
ifneq ($$(findstring $$($1_Type), Byte Short Char), )
132+
$1_ARGS += -KShorterThanInt
133+
endif
134+
endef
135+
136+
################################################################################
137+
# Setup a rule for generating the ScopedMemoryAccess java class
138+
139+
SCOPE_MEMORY_ACCESS_TYPES := Byte Short Char Int Long Float Double
140+
$(foreach t, $(SCOPE_MEMORY_ACCESS_TYPES), \
141+
$(eval $(call GenerateScopedOp,BIN_$t,$t)))
142+
143+
$(SCOPED_MEMORY_ACCESS_DEST): $(BUILD_TOOLS_JDK) $(SCOPED_MEMORY_ACCESS_TEMPLATE) $(SCOPED_MEMORY_ACCESS_BIN_TEMPLATE)
144+
$(call MakeDir, $(SCOPED_MEMORY_ACCESS_GENSRC_DIR))
145+
$(CP) $(SCOPED_MEMORY_ACCESS_TEMPLATE) $(SCOPED_MEMORY_ACCESS_DEST)
146+
$(foreach t, $(SCOPE_MEMORY_ACCESS_TYPES), \
147+
$(TOOL_SPP) -nel -K$(BIN_$t_type) -Dtype=$(BIN_$t_type) -DType=$(BIN_$t_Type) $(BIN_$t_ARGS) \
148+
-i$(SCOPED_MEMORY_ACCESS_BIN_TEMPLATE) -o$(SCOPED_MEMORY_ACCESS_DEST) ;)
149+
$(PRINTF) "}\n" >> $(SCOPED_MEMORY_ACCESS_DEST)
150+
151+
TARGETS += $(SCOPED_MEMORY_ACCESS_DEST)

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ class AnnotationCollector : public ResourceObj{
10861086
_method_InjectedProfile,
10871087
_method_LambdaForm_Compiled,
10881088
_method_Hidden,
1089+
_method_Scoped,
10891090
_method_IntrinsicCandidate,
10901091
_jdk_internal_vm_annotation_Contended,
10911092
_field_Stable,
@@ -2117,6 +2118,11 @@ AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
21172118
if (!privileged) break; // only allow in privileged code
21182119
return _method_Hidden;
21192120
}
2121+
case VM_SYMBOL_ENUM_NAME(jdk_internal_misc_Scoped_signature): {
2122+
if (_location != _in_method) break; // only allow for methods
2123+
if (!privileged) break; // only allow in privileged code
2124+
return _method_Scoped;
2125+
}
21202126
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_IntrinsicCandidate_signature): {
21212127
if (_location != _in_method) break; // only allow for methods
21222128
if (!privileged) break; // only allow in privileged code
@@ -2174,6 +2180,8 @@ void MethodAnnotationCollector::apply_to(const methodHandle& m) {
21742180
m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm);
21752181
if (has_annotation(_method_Hidden))
21762182
m->set_hidden(true);
2183+
if (has_annotation(_method_Scoped))
2184+
m->set_scoped(true);
21772185
if (has_annotation(_method_IntrinsicCandidate) && !m->is_synthetic())
21782186
m->set_intrinsic_candidate(true);
21792187
if (has_annotation(_jdk_internal_vm_annotation_ReservedStackAccess))

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
template(jdk_internal_vm_annotation_DontInline_signature, "Ljdk/internal/vm/annotation/DontInline;") \
303303
template(jdk_internal_vm_annotation_ForceInline_signature, "Ljdk/internal/vm/annotation/ForceInline;") \
304304
template(jdk_internal_vm_annotation_Hidden_signature, "Ljdk/internal/vm/annotation/Hidden;") \
305+
template(jdk_internal_misc_Scoped_signature, "Ljdk/internal/misc/ScopedMemoryAccess$Scoped;") \
305306
template(jdk_internal_vm_annotation_IntrinsicCandidate_signature, "Ljdk/internal/vm/annotation/IntrinsicCandidate;") \
306307
template(jdk_internal_vm_annotation_Stable_signature, "Ljdk/internal/vm/annotation/Stable;") \
307308
/* Support for JSR 292 & invokedynamic (JDK 1.7 and above) */ \

src/hotspot/share/oops/method.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class Method : public Metadata {
9191
_has_injected_profile = 1 << 4,
9292
_running_emcp = 1 << 5,
9393
_intrinsic_candidate = 1 << 6,
94-
_reserved_stack_access = 1 << 7
94+
_reserved_stack_access = 1 << 7,
95+
_scoped = 1 << 8
9596
};
9697
mutable u2 _flags;
9798

@@ -901,6 +902,14 @@ class Method : public Metadata {
901902
_flags = x ? (_flags | _hidden) : (_flags & ~_hidden);
902903
}
903904

905+
bool is_scoped() const {
906+
return (_flags & _scoped) != 0;
907+
}
908+
909+
void set_scoped(bool x) {
910+
_flags = x ? (_flags | _scoped) : (_flags & ~_scoped);
911+
}
912+
904913
bool intrinsic_candidate() {
905914
return (_flags & _intrinsic_candidate) != 0;
906915
}

src/hotspot/share/prims/nativeLookup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "prims/jvmtiExport.hpp"
4040
#include "prims/nativeLookup.hpp"
4141
#include "prims/unsafe.hpp"
42+
#include "prims/scopedMemoryAccess.hpp"
4243
#include "runtime/arguments.hpp"
4344
#include "runtime/handles.inline.hpp"
4445
#include "runtime/interfaceSupport.inline.hpp"
@@ -240,6 +241,7 @@ static JNINativeMethod lookup_special_native_methods[] = {
240241
#if INCLUDE_JFR
241242
{ CC"Java_jdk_jfr_internal_JVM_registerNatives", NULL, FN_PTR(jfr_register_natives) },
242243
#endif
244+
{ CC"Java_jdk_internal_misc_ScopedMemoryAccess_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscScopedMemoryAccessMethods) },
243245
};
244246

245247
static address lookup_special_native(const char* jni_name) {

0 commit comments

Comments
 (0)