Skip to content

Commit

Permalink
[GR-58547] Provide minimal NativeLibraries implementation.
Browse files Browse the repository at this point in the history
PullRequest: graal/18930
  • Loading branch information
fangerer committed Oct 2, 2024
2 parents 9ac72be + 5527938 commit 06bfc92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -251,23 +251,6 @@ private static long findNative(@SuppressWarnings("unused") ClassLoader loader, S
return NativeLibrarySupport.singleton().findSymbol(entryName).rawValue();
}

@Substitute
@TargetElement(onlyWith = JDKLatest.class)
static long findNative(ClassLoader loader, Class<?> clazz, String entryName, String javaName) {
long addr = NativeLibrarySupport.singleton().findSymbol(entryName).rawValue();
if (addr != 0 && loader != null) {
Target_jdk_internal_reflect_Reflection.ensureNativeAccess(clazz, clazz, javaName, true);
}
return addr;
}

/**
* All usages of {@link Target_jdk_internal_loader_NativeLibraries} are substituted currently.
*/
@Delete
@TargetElement(onlyWith = JDKLatest.class)
static native Target_jdk_internal_loader_NativeLibraries nativeLibrariesFor(ClassLoader loader);

@Substitute
@SuppressWarnings({"unused", "static-method"})
Class<?> defineClass(byte[] b, int off, int len) throws ClassFormatError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,50 +24,31 @@
*/
package com.oracle.svm.core.jdk;

import java.util.Map;
import java.util.Set;

import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import jdk.internal.loader.NativeLibraries;

/*
* Substituting the entire class because the original class has fields capturing
* state from the image generator that must not leak into the image heap.
*/
@Substitute
@TargetClass(value = jdk.internal.loader.NativeLibraries.class)
final class Target_jdk_internal_loader_NativeLibraries {

/**
* The NativeLibraries is only used by the `loadLibrary` methods that are substituted, so we do
* not need an instance for now.
*/
@SuppressWarnings("unused")
@Substitute//
public static NativeLibraries newInstance(ClassLoader loader) {
return null;
}
/*
* Fields capturing state from the image generator that must not leak into the image heap.
*/

@Delete //
private Map<?, ?> libraries;
@Delete //
private static Set<String> loadedLibraryNames;

/*
* We are defensive and also handle private native methods by marking them as deleted. If they
* are reachable, the user is certainly doing something wrong. But we do not want to fail with a
* linking error.
*/

@Delete//
private static native boolean load(Target_jdk_internal_loader_NativeLibraries_NativeLibraryImpl impl, String name, boolean isBuiltin, boolean throwExceptionIfFail);
// needs to be explicitly deleted (GR-58623)
@Delete @SuppressWarnings("unused") static final boolean $assertionsDisabled = false;

@Delete//
private static native void unload(String name, boolean isBuiltin, long handle);
@Substitute
public static Target_jdk_internal_loader_NativeLibraries newInstance(@SuppressWarnings("unused") ClassLoader loader) {
return new Target_jdk_internal_loader_NativeLibraries();
}

@Delete
private static native String findBuiltinLib(String name);
@Substitute
@SuppressWarnings("static-method")
public long find(String name) {
return NativeLibrarySupport.singleton().findSymbol(name).rawValue();
}
}

@TargetClass(value = jdk.internal.loader.NativeLibraries.class, innerClass = "NativeLibraryImpl")
Expand Down

0 comments on commit 06bfc92

Please sign in to comment.