Skip to content
Permalink
Browse files

8234049: Implementation of Memory Access API (Incubator)

Co-authored-by: Vlaidmir Ivanov <vladimir.x.ivanov@oracle.com>
Reviewed-by: alanb, psandoz, chegar, rriggs, plevart, briangoetz, jrose, adinn, vlivanov
  • Loading branch information
2 people authored and mcimadamore committed Dec 12, 2019
1 parent 7cdecd8 commit 8f4f088a1293e1d3cb0264861574214db289dd61
Showing with 7,849 additions and 147 deletions.
  1. +2 −0 make/common/Modules.gmk
  2. +107 −0 make/gensrc/GensrcVarHandles.gmk
  3. +3 −1 src/hotspot/share/ci/ciField.cpp
  4. +494 −0 src/java.base/share/classes/java/lang/invoke/AddressVarHandleGenerator.java
  5. +39 −0 src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
  6. +63 −0 src/java.base/share/classes/java/lang/invoke/VarHandleMemoryAddressBase.java
  7. +50 −0 src/java.base/share/classes/java/lang/invoke/VarHandles.java
  8. +6 −1 src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template
  9. +512 −0 src/java.base/share/classes/java/lang/invoke/X-VarHandleMemoryAddressView.java.template
  10. +48 −1 src/java.base/share/classes/java/nio/Buffer.java
  11. +16 −11 src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template
  12. +6 −4 src/java.base/share/classes/java/nio/Direct-X-Buffer-bin.java.template
  13. +25 −15 src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
  14. +61 −27 src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
  15. +8 −6 src/java.base/share/classes/java/nio/MappedByteBuffer.java
  16. +2 −2 src/java.base/share/classes/java/nio/StringCharBuffer.java
  17. +15 −6 src/java.base/share/classes/java/nio/X-Buffer.java.template
  18. +39 −0 src/java.base/share/classes/jdk/internal/access/JavaLangInvokeAccess.java
  19. +32 −0 src/java.base/share/classes/jdk/internal/access/JavaNioAccess.java
  20. +42 −0 src/java.base/share/classes/jdk/internal/access/foreign/MemoryAddressProxy.java
  21. +35 −0 src/java.base/share/classes/jdk/internal/access/foreign/MemorySegmentProxy.java
  22. +36 −0 src/java.base/share/classes/jdk/internal/access/foreign/UnmapperProxy.java
  23. +12 −5 src/java.base/share/classes/module-info.java
  24. +103 −64 src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
  25. +5 −4 src/java.base/share/classes/sun/nio/ch/Util.java
  26. +178 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/AbstractLayout.java
  27. +210 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/GroupLayout.java
  28. +111 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java
  29. +268 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryHandles.java
  30. +445 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java
  31. +138 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayouts.java
  32. +430 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java
  33. +111 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/PaddingLayout.java
  34. +161 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SequenceLayout.java
  35. +140 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/ValueLayout.java
  36. +90 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/package-info.java
  37. +68 −0 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/unsafe/ForeignUnsafe.java
  38. +216 −0 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/LayoutPath.java
  39. +117 −0 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryAddressImpl.java
  40. +119 −0 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryScope.java
  41. +209 −0 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemorySegmentImpl.java
  42. +157 −0 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java
  43. +35 −0 src/jdk.incubator.foreign/share/classes/module-info.java
  44. +4 −0 test/jdk/TEST.groups
  45. +25 −0 test/jdk/java/foreign/TEST.properties
  46. +145 −0 test/jdk/java/foreign/TestArrays.java
  47. +555 −0 test/jdk/java/foreign/TestByteBuffer.java
  48. +96 −0 test/jdk/java/foreign/TestLayoutConstants.java
  49. +137 −0 test/jdk/java/foreign/TestLayoutPaths.java
  50. +289 −0 test/jdk/java/foreign/TestLayouts.java
  51. +459 −0 test/jdk/java/foreign/TestMemoryAccess.java
  52. +137 −0 test/jdk/java/foreign/TestMemoryAlignment.java
  53. +127 −0 test/jdk/java/foreign/TestMemoryCopy.java
  54. +232 −0 test/jdk/java/foreign/TestNative.java
  55. +196 −0 test/jdk/java/foreign/TestSegments.java
  56. +82 −0 test/jdk/java/foreign/TestSharedAccess.java
  57. +97 −0 test/jdk/java/foreign/TestSlices.java
  58. +189 −0 test/jdk/java/foreign/TestVarHandleCombinators.java
  59. +115 −0 test/jdk/java/foreign/libNativeAccess.c
@@ -58,6 +58,7 @@ BOOT_MODULES += \
java.rmi \
java.security.sasl \
java.xml \
jdk.incubator.foreign \
jdk.internal.vm.ci \
jdk.jfr \
jdk.management \
@@ -162,6 +163,7 @@ DOCS_MODULES += \
jdk.jsobject \
jdk.jshell \
jdk.jstatd \
jdk.incubator.foreign \
jdk.localedata \
jdk.management \
jdk.management.agent \
@@ -159,6 +159,108 @@ endef

################################################################################

################################################################################
# Setup a rule for generating a VarHandleMemoryAddress java class
# Param 1 - Variable declaration prefix
# Param 2 - Type with first letter capitalized
define GenerateVarHandleMemoryAddress

$1_Type := $2

$1_FILENAME := $(VARHANDLES_GENSRC_DIR)/VarHandleMemoryAddressAs$$($1_Type)s.java

ifeq ($$($1_Type), Byte)
$1_type := byte
$1_BoxType := $$($1_Type)

$1_rawType := $$($1_type)
$1_RawType := $$($1_Type)
$1_RawBoxType := $$($1_BoxType)

$1_ARGS += -Kbyte
endif

ifeq ($$($1_Type), Short)
$1_type := short
$1_BoxType := $$($1_Type)

$1_rawType := $$($1_type)
$1_RawType := $$($1_Type)
$1_RawBoxType := $$($1_BoxType)
endif

ifeq ($$($1_Type), Char)
$1_type := char
$1_BoxType := Character

$1_rawType := $$($1_type)
$1_RawType := $$($1_Type)
$1_RawBoxType := $$($1_BoxType)
endif

ifeq ($$($1_Type), Int)
$1_type := int
$1_BoxType := Integer

$1_rawType := $$($1_type)
$1_RawType := $$($1_Type)
$1_RawBoxType := $$($1_BoxType)

$1_ARGS += -KCAS
$1_ARGS += -KAtomicAdd
$1_ARGS += -KBitwise
endif

ifeq ($$($1_Type), Long)
$1_type := long
$1_BoxType := $$($1_Type)

$1_rawType := $$($1_type)
$1_RawType := $$($1_Type)
$1_RawBoxType := $$($1_BoxType)

$1_ARGS += -KCAS
$1_ARGS += -KAtomicAdd
$1_ARGS += -KBitwise
endif

ifeq ($$($1_Type), Float)
$1_type := float
$1_BoxType := $$($1_Type)

$1_rawType := int
$1_RawType := Int
$1_RawBoxType := Integer

$1_ARGS += -KCAS
$1_ARGS += -KfloatingPoint
endif

ifeq ($$($1_Type), Double)
$1_type := double
$1_BoxType := $$($1_Type)

$1_rawType := long
$1_RawType := Long
$1_RawBoxType := Long

$1_ARGS += -KCAS
$1_ARGS += -KfloatingPoint
endif

$$($1_FILENAME): $(VARHANDLES_SRC_DIR)/X-VarHandleMemoryAddressView.java.template $(BUILD_TOOLS_JDK)
$$(call MakeDir, $$(@D))
$(RM) $$@
$(TOOL_SPP) -nel -K$$($1_type) \
-Dtype=$$($1_type) -DType=$$($1_Type) -DBoxType=$$($1_BoxType) \
-DrawType=$$($1_rawType) -DRawType=$$($1_RawType) -DRawBoxType=$$($1_RawBoxType) \
$$($1_ARGS) -i$$< -o$$@

GENSRC_VARHANDLES += $$($1_FILENAME)
endef

################################################################################

# List the types to generate source for, with capitalized first letter
VARHANDLES_TYPES := Boolean Byte Short Char Int Long Float Double Reference
$(foreach t, $(VARHANDLES_TYPES), \
@@ -169,6 +271,11 @@ VARHANDLES_BYTE_ARRAY_TYPES := Short Char Int Long Float Double
$(foreach t, $(VARHANDLES_BYTE_ARRAY_TYPES), \
$(eval $(call GenerateVarHandleByteArray,VAR_HANDLE_BYTE_ARRAY_$t,$t)))

# List the types to generate source for, with capitalized first letter
VARHANDLES_MEMORY_ADDRESS_TYPES := Byte Short Char Int Long Float Double
$(foreach t, $(VARHANDLES_MEMORY_ADDRESS_TYPES), \
$(eval $(call GenerateVarHandleMemoryAddress,VAR_HANDLE_MEMORY_ADDRESS_$t,$t)))

GENSRC_JAVA_BASE += $(GENSRC_VARHANDLES)

# Include custom extension post hook
@@ -219,7 +219,9 @@ static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
// Never trust strangely unstable finals: System.out, etc.
return false;
// Even if general trusting is disabled, trust system-built closures in these packages.
if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke") ||
holder->is_in_package("jdk/internal/foreign") || holder->is_in_package("jdk/incubator/foreign") ||
holder->is_in_package("java/lang"))
return true;
// Trust VM unsafe anonymous classes. They are private API (jdk.internal.misc.Unsafe)
// and can't be serialized, so there is no hacking of finals going on with them.

0 comments on commit 8f4f088

Please sign in to comment.
You can’t perform that action at this time.