Skip to content

Commit 3b9bc76

Browse files
dprccichristianhaeubl
authored andcommitted
Implement more JVMTI features.
1 parent 5536434 commit 3b9bc76

File tree

69 files changed

+5642
-221
lines changed

Some content is hidden

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

69 files changed

+5642
-221
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.lang.ref.Reference;
3131

32+
import com.oracle.svm.core.jvmti.JvmtiPostEvents;
3233
import org.graalvm.nativeimage.CurrentIsolate;
3334
import org.graalvm.nativeimage.IsolateThread;
3435
import org.graalvm.nativeimage.Platform;
@@ -169,6 +170,8 @@ public void collectionHint(boolean fullGC) {
169170

170171
private void collect(GCCause cause, boolean forceFullGC) {
171172
if (!hasNeverCollectPolicy()) {
173+
JvmtiPostEvents.postGarbageCollectionStart();
174+
JvmtiPostEvents.postGarbageCollectionFinish();
172175
boolean outOfMemory = collectWithoutAllocating(cause, forceFullGC);
173176
if (outOfMemory) {
174177
throw OutOfMemoryUtil.heapSizeExceeded();

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ImageHeapWalker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static boolean walkPartitionInline(Object firstObject, Object lastObject
126126

127127
@Uninterruptible(reason = "Bridge between uninterruptible and potentially interruptible code.", mayBeInlined = true, calleeMustBe = false)
128128
private static boolean visitObject(ObjectVisitor visitor, Object currentObject) {
129-
return visitor.visitObject(currentObject);
129+
return visitor. visitObject(currentObject);
130130
}
131131

132132
@Uninterruptible(reason = "Bridge between uninterruptible and potentially interruptible code.", mayBeInlined = true, calleeMustBe = false)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,16 @@ public static void updateMaxJavaStackTraceDepth(EconomicMap<OptionKey<?>, Object
467467
@Option(help = "Enable JVM Tool Interface (JVMTI) support.", type = OptionType.User)//
468468
public static final HostedOptionKey<Boolean> JVMTI = new HostedOptionKey<>(false);
469469

470-
// TEMP (chaeubl): we need to support multiple values
471-
@Option(help = "Loads the specified native agent library specified by the absolute path name. " +
472-
"After the library path, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
473-
public static final RuntimeOptionKey<String> AgentPath = new RuntimeOptionKey<>(null);
474-
475470
// TEMP (chaeubl): we need to support multiple values
476471
@Option(help = "Loads the specified native agent library. " +
477472
"After the library name, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
478473
public static final RuntimeOptionKey<String> AgentLib = new RuntimeOptionKey<>(null);
479474

475+
// TEMP (chaeubl): we need to support multiple values
476+
@Option(help = "Loads the specified native agent library specified by the absolute path name. " +
477+
"After the library path, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
478+
public static final RuntimeOptionKey<String> AgentPath = new RuntimeOptionKey<>(null);
479+
480480
@Option(help = "Alignment of AOT and JIT compiled code in bytes.")//
481481
public static final HostedOptionKey<Integer> CodeAlignment = new HostedOptionKey<>(16);
482482

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
import java.util.Map;
3535

36+
import com.oracle.svm.core.jvmti.JvmtiEnvManager;
37+
import com.oracle.svm.core.jvmti.JvmtiManager;
38+
import com.oracle.svm.core.jvmti.JvmtiPostEvents;
3639
import org.graalvm.nativeimage.CurrentIsolate;
3740
import org.graalvm.nativeimage.ImageSingletons;
3841
import org.graalvm.nativeimage.Isolate;
@@ -401,6 +404,9 @@ private static int initializeIsolateInterruptibly1(CEntryPointCreateIsolateParam
401404

402405
if (SubstrateOptions.JVMTI.getValue()) {
403406
JvmtiAgents.singleton().load();
407+
408+
//JvmtiPostEvents.postVMInit();
409+
JvmtiPostEvents.postVMStart();
404410
}
405411

406412
assert !isolateInitialized;
@@ -639,9 +645,12 @@ private static boolean initiateTearDownIsolateInterruptibly() {
639645
VMThreads.singleton().threadExit();
640646

641647
if (SubstrateOptions.JVMTI.getValue()) {
648+
JvmtiPostEvents.postVMDeath();
649+
JvmtiManager.freeAllJvmtiClassesUnmanagedMemory();
642650
JvmtiAgents.singleton().unload();
643651
}
644652

653+
645654
return true;
646655
}
647656

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/headers/LibCSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.oracle.svm.core.memory.NativeMemory;
3535

3636
/** Platform-independent LibC support. Don't use this class directly, use {@link LibC} instead. */
37-
public interface LibCSupport {
37+
public interface LibCSupport {
3838
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
3939
int errno();
4040

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,7 @@ private ClassRepository getGenericInfo() {
18011801
return companion.getGenericInfo(this);
18021802
}
18031803

1804+
18041805
ClassRepository computeGenericInfo() {
18051806
String genericSignature = getGenericSignature0();
18061807
if (genericSignature == null) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibraries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected static PointerBase findSymbol(Collection<PlatformNativeLibrarySupport.
6868

6969
/** Returns the directory containing the native image, or {@code null}. */
7070
@NeverInline("Reads the return address.")
71-
private static String getImageDirectory() {
71+
public static String getImageDirectory() {
7272
/*
7373
* While one might expect code for shared libraries to work for executables as well, this is
7474
* not necessarily the case. For example, `dladdr` on Linux returns `argv[0]` for

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/UninterruptibleUtils.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,21 @@ public static int modifiedUTF8Length(java.lang.String string, boolean addNullTer
602602
return result + (addNullTerminator ? 1 : 0);
603603
}
604604

605+
//TODO @dprcci FINISH THAT TłOMORROW
606+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
607+
public static int modifiedUTF8LengthCharArray(char[] buffer, int bufferLength, boolean addNullTerminator, CharReplacer replacer) {
608+
int result = 0;
609+
for (int index = 0; index < bufferLength; index++) {
610+
char ch = buffer[index];
611+
if (replacer != null) {
612+
ch = replacer.replace(ch);
613+
}
614+
result += modifiedUTF8Length(ch);
615+
}
616+
617+
return result + (addNullTerminator ? 1 : 0);
618+
}
619+
605620
/**
606621
* Writes the encoded {@code string} into the given {@code buffer} using the modified UTF8
607622
* encoding (null characters that are present in the input will be encoded in a way that
@@ -637,6 +652,29 @@ public static Pointer toModifiedUTF8(java.lang.String string, int stringLength,
637652
VMError.guarantee(pos.belowOrEqual(bufferEnd), "Must not write out of bounds.");
638653
return pos;
639654
}
655+
656+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
657+
public static Pointer toModifiedUTF8FromCharArray(char[] charArray, int endIndex, Pointer buffer, Pointer bufferEnd, boolean addNullTerminator) {
658+
return toModifiedUTF8FromCharArray(charArray, endIndex, buffer, bufferEnd, addNullTerminator, null);
659+
}
660+
661+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
662+
public static Pointer toModifiedUTF8FromCharArray(char[] charArray, int endIndex, Pointer buffer, Pointer bufferEnd, boolean addNullTerminator, CharReplacer replacer) {
663+
Pointer pos = buffer;
664+
for (int i = 0; i < endIndex; i++) {
665+
char ch = charArray[i];
666+
if (replacer != null) {
667+
ch = replacer.replace(ch);
668+
}
669+
pos = writeModifiedUTF8(pos, ch);
670+
}
671+
if (addNullTerminator) {
672+
pos.writeByte(0, (byte) 0);
673+
pos = pos.add(1);
674+
}
675+
VMError.guarantee(pos.belowOrEqual(bufferEnd), "Must not write out of bounds.");
676+
return pos;
677+
}
640678
}
641679

642680
@FunctionalInterface

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/access/JNIAccessibleField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
/**
4545
* Information on a field that can be looked up and accessed via JNI.
4646
*/
47-
public final class JNIAccessibleField extends JNIAccessibleMember {
47+
public final class JNIAccessibleField extends JNIAccessibleMember {
4848
/* 10000000...0 */
4949
private static final UnsignedWord ID_STATIC_FLAG = WordFactory.unsigned(-1L).unsignedShiftRight(1).add(1);
5050
/* 01000000...0 */

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jni/access/JNIAccessibleMethod.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.lang.reflect.Modifier;
2828

2929
import org.graalvm.collections.EconomicSet;
30-
import jdk.graal.compiler.nodes.NamedLocationIdentity;
31-
import jdk.graal.compiler.word.BarrieredAccess;
3230
import org.graalvm.nativeimage.Platform.HOSTED_ONLY;
3331
import org.graalvm.nativeimage.Platforms;
3432
import org.graalvm.nativeimage.c.function.CodePointer;
@@ -42,6 +40,8 @@
4240
import com.oracle.svm.core.util.VMError;
4341
import com.oracle.svm.util.ReflectionUtil;
4442

43+
import jdk.graal.compiler.nodes.NamedLocationIdentity;
44+
import jdk.graal.compiler.word.BarrieredAccess;
4545
import jdk.vm.ci.meta.MetaAccessProvider;
4646
import jdk.vm.ci.meta.ResolvedJavaField;
4747

@@ -129,10 +129,12 @@ boolean isPublic() {
129129
return Modifier.isPublic(modifiers);
130130
}
131131

132-
boolean isStatic() {
133-
return Modifier.isStatic(modifiers);
132+
boolean isNative() {
133+
return Modifier.isNative(modifiers);
134134
}
135135

136+
boolean isStatic() {return Modifier.isStatic(modifiers);}
137+
136138
@Platforms(HOSTED_ONLY.class)
137139
public void finishBeforeCompilation(EconomicSet<Class<?>> hidingSubclasses, int vtableEntryOffset, CodePointer nonvirtualEntry, PointerBase newObjectEntry, CodePointer callWrapperEntry,
138140
CodePointer varargs, CodePointer array, CodePointer valist, CodePointer varargsNonvirtual, CodePointer arrayNonvirtual, CodePointer valistNonvirtual) {

0 commit comments

Comments
 (0)