Skip to content

Commit 6bb1798

Browse files
dprccichristianhaeubl
authored andcommitted
Implement more JVMTI features.
1 parent ebb1d4b commit 6bb1798

File tree

69 files changed

+5635
-218
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

+5635
-218
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
@@ -31,6 +31,7 @@
3131

3232
import java.lang.ref.Reference;
3333

34+
import com.oracle.svm.core.jvmti.JvmtiPostEvents;
3435
import org.graalvm.nativeimage.CurrentIsolate;
3536
import org.graalvm.nativeimage.IsolateThread;
3637
import org.graalvm.nativeimage.Platform;
@@ -177,6 +178,8 @@ public void collectionHint(boolean fullGC) {
177178

178179
private void collect(GCCause cause, boolean forceFullGC) {
179180
if (!hasNeverCollectPolicy()) {
181+
JvmtiPostEvents.postGarbageCollectionStart();
182+
JvmtiPostEvents.postGarbageCollectionFinish();
180183
boolean outOfMemory = collectWithoutAllocating(cause, forceFullGC);
181184
if (outOfMemory) {
182185
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
@@ -127,7 +127,7 @@ private static boolean walkPartitionInline(Object firstObject, Object lastObject
127127

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

133133
@AlwaysInline("de-virtualize calls to ObjectReferenceVisitor")

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
@@ -634,16 +634,16 @@ public static void updateMaxJavaStackTraceDepth(EconomicMap<OptionKey<?>, Object
634634
@Option(help = "Enable JVM Tool Interface (JVMTI) support.", type = OptionType.User)//
635635
public static final HostedOptionKey<Boolean> JVMTI = new HostedOptionKey<>(false);
636636

637-
// TEMP (chaeubl): we need to support multiple values
638-
@Option(help = "Loads the specified native agent library specified by the absolute path name. " +
639-
"After the library path, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
640-
public static final RuntimeOptionKey<String> AgentPath = new RuntimeOptionKey<>(null);
641-
642637
// TEMP (chaeubl): we need to support multiple values
643638
@Option(help = "Loads the specified native agent library. " +
644639
"After the library name, a comma-separated list of options specific to the library can be used.", type = OptionType.User)//
645640
public static final RuntimeOptionKey<String> AgentLib = new RuntimeOptionKey<>(null);
646641

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

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
@@ -32,6 +32,9 @@
3232

3333
import java.util.Map;
3434

35+
import com.oracle.svm.core.jvmti.JvmtiEnvManager;
36+
import com.oracle.svm.core.jvmti.JvmtiManager;
37+
import com.oracle.svm.core.jvmti.JvmtiPostEvents;
3538
import org.graalvm.nativeimage.CurrentIsolate;
3639
import org.graalvm.nativeimage.ImageSingletons;
3740
import org.graalvm.nativeimage.Isolate;
@@ -399,6 +402,9 @@ private static int initializeIsolateInterruptibly1(CEntryPointCreateIsolateParam
399402

400403
if (SubstrateOptions.JVMTI.getValue()) {
401404
JvmtiAgents.singleton().load();
405+
406+
//JvmtiPostEvents.postVMInit();
407+
JvmtiPostEvents.postVMStart();
402408
}
403409

404410
assert !isolateInitialized;
@@ -633,9 +639,12 @@ private static boolean initiateTearDownIsolateInterruptibly() {
633639
VMThreads.singleton().threadExit();
634640

635641
if (SubstrateOptions.JVMTI.getValue()) {
642+
JvmtiPostEvents.postVMDeath();
643+
JvmtiManager.freeAllJvmtiClassesUnmanagedMemory();
636644
JvmtiAgents.singleton().unload();
637645
}
638646

647+
639648
return true;
640649
}
641650

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
@@ -1843,6 +1843,7 @@ private ClassRepository getGenericInfo() {
18431843
return companion.getGenericInfo(this);
18441844
}
18451845

1846+
18461847
ClassRepository computeGenericInfo() {
18471848
String genericSignature = getGenericSignature0();
18481849
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
@@ -605,6 +605,21 @@ public static int modifiedUTF8Length(java.lang.String string, boolean addNullTer
605605
return result + (addNullTerminator ? 1 : 0);
606606
}
607607

608+
//TODO @dprcci FINISH THAT TłOMORROW
609+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
610+
public static int modifiedUTF8LengthCharArray(char[] buffer, int bufferLength, boolean addNullTerminator, CharReplacer replacer) {
611+
int result = 0;
612+
for (int index = 0; index < bufferLength; index++) {
613+
char ch = buffer[index];
614+
if (replacer != null) {
615+
ch = replacer.replace(ch);
616+
}
617+
result += modifiedUTF8Length(ch);
618+
}
619+
620+
return result + (addNullTerminator ? 1 : 0);
621+
}
622+
608623
/**
609624
* Writes the encoded {@code string} into the given {@code buffer} using the modified UTF8
610625
* encoding (null characters that are present in the input will be encoded in a way that
@@ -641,6 +656,29 @@ public static Pointer toModifiedUTF8(java.lang.String string, int stringLength,
641656
return pos;
642657
}
643658

659+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
660+
public static Pointer toModifiedUTF8FromCharArray(char[] charArray, int endIndex, Pointer buffer, Pointer bufferEnd, boolean addNullTerminator) {
661+
return toModifiedUTF8FromCharArray(charArray, endIndex, buffer, bufferEnd, addNullTerminator, null);
662+
}
663+
664+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
665+
public static Pointer toModifiedUTF8FromCharArray(char[] charArray, int endIndex, Pointer buffer, Pointer bufferEnd, boolean addNullTerminator, CharReplacer replacer) {
666+
Pointer pos = buffer;
667+
for (int i = 0; i < endIndex; i++) {
668+
char ch = charArray[i];
669+
if (replacer != null) {
670+
ch = replacer.replace(ch);
671+
}
672+
pos = writeModifiedUTF8(pos, ch);
673+
}
674+
if (addNullTerminator) {
675+
pos.writeByte(0, (byte) 0);
676+
pos = pos.add(1);
677+
}
678+
VMError.guarantee(pos.belowOrEqual(bufferEnd), "Must not write out of bounds.");
679+
return pos;
680+
}
681+
644682
/**
645683
* Returns a character from a string at {@code index} position based on the encoding format.
646684
*/

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ boolean isPublic() {
157157
return Modifier.isPublic(modifiers);
158158
}
159159

160-
boolean isStatic() {
161-
return Modifier.isStatic(modifiers);
160+
boolean isNative() {
161+
return Modifier.isNative(modifiers);
162162
}
163163

164+
boolean isStatic() {return Modifier.isStatic(modifiers);}
165+
164166
@Platforms(HOSTED_ONLY.class)
165167
public void finishBeforeCompilation(EconomicSet<Class<?>> hidingSubclasses, int vtableOffsetEntry, int interfaceTypeIDEntry, CodePointer nonvirtualEntry, PointerBase newObjectEntry,
166168
CodePointer callWrapperEntry, CodePointer varargs, CodePointer array, CodePointer valist, CodePointer varargsNonvirtual, CodePointer arrayNonvirtual,

0 commit comments

Comments
 (0)