Skip to content

Commit bd3fec3

Browse files
committed
8344086: Remove security manager dependency in FFM
Reviewed-by: mcimadamore, rriggs, jvernee
1 parent 916694f commit bd3fec3

11 files changed

Lines changed: 39 additions & 67 deletions

File tree

src/java.base/share/classes/jdk/internal/foreign/CABI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
2323
* questions.
2424
*
2525
*/
26+
2627
package jdk.internal.foreign;
2728

2829
import jdk.internal.foreign.abi.fallback.FallbackLinker;
@@ -31,7 +32,6 @@
3132
import jdk.internal.util.StaticProperty;
3233

3334
import static java.lang.foreign.ValueLayout.ADDRESS;
34-
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
3535

3636
public enum CABI {
3737
SYS_V,
@@ -50,7 +50,7 @@ public enum CABI {
5050
private static final CABI CURRENT = computeCurrent();
5151

5252
private static CABI computeCurrent() {
53-
String abi = privilegedGetProperty("jdk.internal.foreign.CABI");
53+
String abi = System.getProperty("jdk.internal.foreign.CABI");
5454
if (abi != null) {
5555
return CABI.valueOf(abi);
5656
}

src/java.base/share/classes/jdk/internal/foreign/SegmentBulkOperations.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import jdk.internal.util.Architecture;
3030
import jdk.internal.util.ArraysSupport;
3131
import jdk.internal.vm.annotation.ForceInline;
32-
import sun.security.action.GetIntegerAction;
3332

3433
import java.lang.foreign.MemorySegment;
3534

@@ -293,7 +292,7 @@ private static long vectorizedMismatchLargeForBytes(MemorySessionImpl aSession,
293292

294293
// The returned value is in the interval [0, 2^30]
295294
static int powerOfPropertyOr(String name, int defaultPower) {
296-
final int power = GetIntegerAction.privilegedGetProperty(PROPERTY_PATH + name, defaultPower);
295+
final int power = Integer.getInteger(PROPERTY_PATH + name, defaultPower);
297296
return 1 << Math.clamp(power, 0, Integer.SIZE - 2);
298297
}
299298

src/java.base/share/classes/jdk/internal/foreign/StringSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,6 @@
2929
import jdk.internal.access.SharedSecrets;
3030
import jdk.internal.foreign.abi.SharedUtils;
3131
import jdk.internal.util.ArraysSupport;
32-
import sun.security.action.GetPropertyAction;
3332

3433
import java.lang.foreign.MemorySegment;
3534
import java.nio.charset.Charset;

src/java.base/share/classes/jdk/internal/foreign/SystemLookup.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
import java.lang.invoke.MethodHandles;
3030
import java.nio.file.Files;
3131
import java.nio.file.Path;
32-
import java.security.AccessController;
33-
import java.security.PrivilegedAction;
3432
import java.util.Objects;
3533
import java.util.Optional;
3634
import java.util.function.Function;
3735
import jdk.internal.loader.NativeLibrary;
3836
import jdk.internal.loader.RawNativeLibraries;
39-
import sun.security.action.GetPropertyAction;
37+
import jdk.internal.util.OperatingSystem;
4038

4139
import static java.lang.foreign.ValueLayout.ADDRESS;
4240

@@ -60,7 +58,7 @@ private SystemLookup() { }
6058

6159
private static SymbolLookup makeSystemLookup() {
6260
try {
63-
if (Utils.IS_WINDOWS) {
61+
if (OperatingSystem.isWindows()) {
6462
return makeWindowsLookup();
6563
} else {
6664
return libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
@@ -74,24 +72,12 @@ private static SymbolLookup makeSystemLookup() {
7472
}
7573

7674
private static SymbolLookup makeWindowsLookup() {
77-
@SuppressWarnings("removal")
78-
String systemRoot = AccessController.doPrivileged(new PrivilegedAction<>() {
79-
@Override
80-
public String run() {
81-
return System.getenv("SystemRoot");
82-
}
83-
});
75+
String systemRoot = System.getenv("SystemRoot");
8476
Path system32 = Path.of(systemRoot, "System32");
8577
Path ucrtbase = system32.resolve("ucrtbase.dll");
8678
Path msvcrt = system32.resolve("msvcrt.dll");
8779

88-
@SuppressWarnings("removal")
89-
boolean useUCRT = AccessController.doPrivileged(new PrivilegedAction<>() {
90-
@Override
91-
public Boolean run() {
92-
return Files.exists(ucrtbase);
93-
}
94-
});
80+
boolean useUCRT = Files.exists(ucrtbase);
9581
Path stdLib = useUCRT ? ucrtbase : msvcrt;
9682
SymbolLookup lookup = libLookup(libs -> libs.load(stdLib));
9783

@@ -139,8 +125,8 @@ private static SymbolLookup libLookup(Function<RawNativeLibraries, NativeLibrary
139125
* Returns the path of the given library name from JDK
140126
*/
141127
private static Path jdkLibraryPath(String name) {
142-
Path javahome = Path.of(GetPropertyAction.privilegedGetProperty("java.home"));
143-
String lib = Utils.IS_WINDOWS ? "bin" : "lib";
128+
Path javahome = Path.of(System.getProperty("java.home"));
129+
String lib = OperatingSystem.isWindows() ? "bin" : "lib";
144130
String libname = System.mapLibraryName(name);
145131
return javahome.resolve(lib).resolve(libname);
146132
}

src/java.base/share/classes/jdk/internal/foreign/Utils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,11 @@
4848
import jdk.internal.vm.annotation.ForceInline;
4949
import sun.invoke.util.Wrapper;
5050

51-
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
52-
5351
/**
5452
* This class contains misc helper functions to support creation of memory segments.
5553
*/
5654
public final class Utils {
5755

58-
public static final boolean IS_WINDOWS = privilegedGetProperty("os.name").startsWith("Windows");
59-
6056
// Suppresses default constructor, ensuring non-instantiability.
6157
private Utils() {}
6258

src/java.base/share/classes/jdk/internal/foreign/abi/BindingSpecializer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25+
2526
package jdk.internal.foreign.abi;
2627

2728
import java.lang.classfile.Annotation;
@@ -48,9 +49,6 @@
4849
import jdk.internal.foreign.abi.Binding.VMLoad;
4950
import jdk.internal.foreign.abi.Binding.VMStore;
5051
import jdk.internal.vm.annotation.ForceInline;
51-
import sun.security.action.GetBooleanAction;
52-
import sun.security.action.GetIntegerAction;
53-
import sun.security.action.GetPropertyAction;
5452

5553
import java.io.IOException;
5654
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
@@ -78,11 +76,11 @@
7876

7977
public class BindingSpecializer {
8078
private static final String DUMP_CLASSES_DIR
81-
= GetPropertyAction.privilegedGetProperty("jdk.internal.foreign.abi.Specializer.DUMP_CLASSES_DIR");
79+
= System.getProperty("jdk.internal.foreign.abi.Specializer.DUMP_CLASSES_DIR");
8280
private static final boolean PERFORM_VERIFICATION
83-
= GetBooleanAction.privilegedGetProperty("jdk.internal.foreign.abi.Specializer.PERFORM_VERIFICATION");
81+
= Boolean.getBoolean("jdk.internal.foreign.abi.Specializer.PERFORM_VERIFICATION");
8482
private static final int SCOPE_DEDUP_DEPTH
85-
= GetIntegerAction.privilegedGetProperty("jdk.internal.foreign.abi.Specializer.SCOPE_DEDUP_DEPTH", 2);
83+
= Integer.getInteger("jdk.internal.foreign.abi.Specializer.SCOPE_DEDUP_DEPTH", 2);
8684

8785
// Bunch of helper constants
8886
private static final int CLASSFILE_VERSION = ClassFileFormatVersion.latest().major();

src/java.base/share/classes/jdk/internal/foreign/abi/CallingSequenceBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,6 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25+
2526
package jdk.internal.foreign.abi;
2627

2728
import jdk.internal.foreign.Utils;
@@ -38,7 +39,6 @@
3839
import jdk.internal.foreign.abi.Binding.ShiftRight;
3940
import jdk.internal.foreign.abi.Binding.VMLoad;
4041
import jdk.internal.foreign.abi.Binding.VMStore;
41-
import sun.security.action.GetPropertyAction;
4242

4343
import java.lang.foreign.FunctionDescriptor;
4444
import java.lang.foreign.MemoryLayout;
@@ -54,7 +54,7 @@
5454

5555
public class CallingSequenceBuilder {
5656
private static final boolean VERIFY_BINDINGS = Boolean.parseBoolean(
57-
GetPropertyAction.privilegedGetProperty("java.lang.foreign.VERIFY_BINDINGS", "true"));
57+
System.getProperty("java.lang.foreign.VERIFY_BINDINGS", "true"));
5858

5959
private final ABIDescriptor abi;
6060
private final LinkerOptions linkerOptions;

src/java.base/share/classes/jdk/internal/foreign/abi/CapturableState.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,9 +22,10 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25+
2526
package jdk.internal.foreign.abi;
2627

27-
import jdk.internal.foreign.Utils;
28+
import jdk.internal.util.OperatingSystem;
2829

2930
import java.lang.foreign.MemoryLayout;
3031
import java.lang.foreign.StructLayout;
@@ -35,8 +36,8 @@
3536
import static java.lang.foreign.ValueLayout.JAVA_INT;
3637

3738
public enum CapturableState {
38-
GET_LAST_ERROR ("GetLastError", JAVA_INT, 1 << 0, Utils.IS_WINDOWS),
39-
WSA_GET_LAST_ERROR("WSAGetLastError", JAVA_INT, 1 << 1, Utils.IS_WINDOWS),
39+
GET_LAST_ERROR ("GetLastError", JAVA_INT, 1 << 0, OperatingSystem.isWindows()),
40+
WSA_GET_LAST_ERROR("WSAGetLastError", JAVA_INT, 1 << 1, OperatingSystem.isWindows()),
4041
ERRNO ("errno", JAVA_INT, 1 << 2, true);
4142

4243
public static final StructLayout LAYOUT = MemoryLayout.structLayout(

src/java.base/share/classes/jdk/internal/foreign/abi/DowncallLinker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25+
2526
package jdk.internal.foreign.abi;
2627

2728
import jdk.internal.access.JavaLangInvokeAccess;
2829
import jdk.internal.access.SharedSecrets;
2930
import jdk.internal.invoke.MhUtil;
30-
import sun.security.action.GetPropertyAction;
3131

3232
import java.lang.foreign.AddressLayout;
3333
import java.lang.foreign.Arena;
@@ -52,7 +52,7 @@
5252

5353
public class DowncallLinker {
5454
private static final boolean USE_SPEC = Boolean.parseBoolean(
55-
GetPropertyAction.privilegedGetProperty("jdk.internal.foreign.DowncallLinker.USE_SPEC", "true"));
55+
System.getProperty("jdk.internal.foreign.DowncallLinker.USE_SPEC", "true"));
5656

5757
private static final JavaLangInvokeAccess JLIA = SharedSecrets.getJavaLangInvokeAccess();
5858

src/java.base/share/classes/jdk/internal/foreign/abi/UpcallLinker.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
2626
package jdk.internal.foreign.abi;
2727

2828
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
29-
import sun.security.action.GetPropertyAction;
3029

3130
import java.lang.foreign.Arena;
3231
import java.lang.foreign.MemorySegment;
@@ -43,13 +42,12 @@
4342
import static java.lang.invoke.MethodHandles.insertArguments;
4443
import static java.lang.invoke.MethodHandles.lookup;
4544
import static java.lang.invoke.MethodType.methodType;
46-
import static sun.security.action.GetBooleanAction.privilegedGetProperty;
4745

4846
public class UpcallLinker {
4947
private static final boolean DEBUG =
50-
privilegedGetProperty("jdk.internal.foreign.UpcallLinker.DEBUG");
48+
Boolean.getBoolean("jdk.internal.foreign.UpcallLinker.DEBUG");
5149
private static final boolean USE_SPEC = Boolean.parseBoolean(
52-
GetPropertyAction.privilegedGetProperty("jdk.internal.foreign.UpcallLinker.USE_SPEC", "true"));
50+
System.getProperty("jdk.internal.foreign.UpcallLinker.USE_SPEC", "true"));
5351

5452
private static final MethodHandle MH_invokeInterpBindings;
5553

0 commit comments

Comments
 (0)