Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [GR-45171] Basic JVMTI infrastructure. #8507

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -65,7 +65,7 @@
* The receiver is the pointer to the struct that is accessed, i.e., the base address of the memory
* access.
* <p>
* The {@code FieldType} must be must be a primitive integer type or a {@link WordBase word type}.
* The {@code FieldType} must be a primitive integer type or a {@link WordBase word type}.
* <p>
* The optional parameter {@code locationIdentity} specifies the {@link LocationIdentity} to be used
* for the memory access. Two memory accesses with two different location identities are guaranteed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,17 @@ public static void updateMaxJavaStackTraceDepth(EconomicMap<OptionKey<?>, Object
@Option(help = "JNI functions will return more specific error codes.", type = OptionType.User)//
public static final HostedOptionKey<Boolean> JNIEnhancedErrorCodes = new HostedOptionKey<>(false);

@Option(help = "Enable JVM Tool Interface (JVMTI) support.", type = OptionType.User)//
public static final HostedOptionKey<Boolean> JVMTI = new HostedOptionKey<>(false);

@Option(help = "Loads the specified native agent library. " +
"After the library name, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
public static final RuntimeOptionKey<String> JVMTIAgentLib = new RuntimeOptionKey<>(null);

@Option(help = "Loads the specified native agent library specified by the absolute path name. " +
"After the library path, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
public static final RuntimeOptionKey<String> JVMTIAgentPath = new RuntimeOptionKey<>(null);

@Option(help = "Alignment of AOT and JIT compiled code in bytes.")//
public static final HostedOptionKey<Integer> CodeAlignment = new HostedOptionKey<>(16);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected static PointerBase findSymbol(Collection<PlatformNativeLibrarySupport.

/** Returns the directory containing the native image, or {@code null}. */
@NeverInline("Reads the return address.")
private static String getImageDirectory() {
public static String getImageDirectory() {
/*
* While one might expect code for shared libraries to work for executables as well, this is
* not necessarily the case. For example, `dladdr` on Linux returns `argv[0]` for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.lang.reflect.Modifier;

import org.graalvm.collections.EconomicSet;
import jdk.graal.compiler.nodes.NamedLocationIdentity;
import jdk.graal.compiler.word.BarrieredAccess;
import org.graalvm.nativeimage.Platform.HOSTED_ONLY;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.function.CodePointer;
Expand All @@ -42,6 +40,8 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.nodes.NamedLocationIdentity;
import jdk.graal.compiler.word.BarrieredAccess;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaField;

Expand Down Expand Up @@ -129,6 +129,10 @@ boolean isPublic() {
return Modifier.isPublic(modifiers);
}

public boolean isNative() {
return Modifier.isNative(modifiers);
}

boolean isStatic() {
return Modifier.isStatic(modifiers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.graalvm.collections.Equivalence;
import org.graalvm.collections.MapCursor;
import org.graalvm.collections.UnmodifiableMapCursor;
import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform.HOSTED_ONLY;
Expand All @@ -53,6 +52,7 @@
import com.oracle.svm.core.util.ImageHeapMap;
import com.oracle.svm.core.util.Utf8.WrappedAsciiCString;

import jdk.graal.compiler.word.Word;
import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.Signature;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
import com.oracle.svm.core.jni.headers.JNIJavaVMOption;
import com.oracle.svm.core.jni.headers.JNIJavaVMPointer;
import com.oracle.svm.core.jni.headers.JNIVersion;
import com.oracle.svm.core.jvmti.JvmtiEnvs;
import com.oracle.svm.core.jvmti.headers.JvmtiExternalEnv;
import com.oracle.svm.core.jvmti.headers.JvmtiVersion;
import com.oracle.svm.core.log.FunctionPointerLogHandler;
import com.oracle.svm.core.memory.UntrackedNullableNativeMemory;
import com.oracle.svm.core.monitor.MonitorInflationCause;
Expand Down Expand Up @@ -299,8 +302,17 @@ static int DestroyJavaVM(JNIJavaVM vm) {
@CEntryPointOptions(prologue = JNIGetEnvPrologue.class)
@SuppressWarnings("unused")
static int GetEnv(JNIJavaVM vm, WordPointer env, int version) {
env.write(JNIThreadLocalEnvironment.getAddress());
return JNIErrors.JNI_OK();
if (SubstrateOptions.JVMTI.getValue() && JvmtiVersion.isSupported(version)) {
JvmtiExternalEnv jvmtiEnv = JvmtiEnvs.singleton().create();
env.write(jvmtiEnv);
return JNIErrors.JNI_OK();
} else if (JNIVersion.isSupported(version)) {
env.write(JNIThreadLocalEnvironment.getAddress());
return JNIErrors.JNI_OK();
} else {
env.write(WordFactory.nullPointer());
return JNIErrors.JNI_EVERSION();
}
}

// Checkstyle: resume
Expand All @@ -316,14 +328,10 @@ static class Support {

static class JNIGetEnvPrologue implements CEntryPointOptions.Prologue {
@Uninterruptible(reason = "prologue")
static int enter(JNIJavaVM vm, WordPointer env, int version) {
static int enter(JNIJavaVM vm, WordPointer env) {
if (vm.isNull() || env.isNull()) {
return JNIErrors.JNI_ERR();
}
if (!JNIVersion.isSupported(version)) {
env.write(WordFactory.nullPointer());
return JNIErrors.JNI_EVERSION();
}
if (!CEntryPointActions.isCurrentThreadAttachedTo(vm.getFunctions().getIsolate())) {
env.write(WordFactory.nullPointer());
return JNIErrors.JNI_EDETACHED();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jni.headers;

import org.graalvm.nativeimage.c.struct.CPointerTo;
import org.graalvm.word.PointerBase;

@CPointerTo(JNIFieldId.class)
public interface JNIFieldIdPointer extends PointerBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jni.headers;

import org.graalvm.nativeimage.c.struct.CPointerTo;
import org.graalvm.word.PointerBase;

@CPointerTo(JNIFieldIdPointer.class)
public interface JNIFieldIdPointerPointer extends PointerBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jni.headers;

import org.graalvm.nativeimage.c.struct.CPointerTo;
import org.graalvm.word.PointerBase;

@CPointerTo(JNIMethodId.class)
public interface JNIMethodIdPointer extends PointerBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jni.headers;

import org.graalvm.nativeimage.c.struct.CPointerTo;
import org.graalvm.word.PointerBase;

@CPointerTo(JNIMethodIdPointer.class)
public interface JNIMethodIdPointerPointer extends PointerBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jni.headers;

import org.graalvm.nativeimage.c.struct.CPointerTo;
import org.graalvm.word.PointerBase;

@CPointerTo(JNINativeInterface.class)
public interface JNINativeInterfacePointer extends PointerBase {
}