Skip to content

Commit da41764

Browse files
committed
[GR-64940] Shared arena: support vector api signatures.
PullRequest: graal/20788
2 parents 83201c5 + 3ce50cb commit da41764

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SharedGraphBuilderPhase.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343
import java.util.Objects;
4444

45+
import com.oracle.svm.hosted.substitute.SubstitutionType;
4546
import org.graalvm.nativeimage.AnnotationAccess;
4647

4748
import com.oracle.graal.pointsto.constraints.TypeInstantiationException;
@@ -180,6 +181,7 @@ public abstract static class SharedBytecodeParser extends BytecodeParser {
180181
private static final Class<?> SCOPED_SUBSTRATE_ANNOTATION;
181182
private static final Executable SESSION_EXCEPTION_HANDLER_METHOD;
182183
private static final Class<?> MAPPED_MEMORY_UTILS_PROXY_CLASS;
184+
private static final Class<?> ABSTRACT_MEMORY_SEGMENT_IMPL_CLASS;
183185

184186
static {
185187
SCOPED_SUBSTRATE_ANNOTATION = ReflectionUtil.lookupClass(true, "com.oracle.svm.core.foreign.Target_jdk_internal_misc_ScopedMemoryAccess_Scoped");
@@ -188,6 +190,7 @@ public abstract static class SharedBytecodeParser extends BytecodeParser {
188190
? ReflectionUtil.lookupMethod(substrateForeignUtilClass, "sessionExceptionHandler", MemorySessionImpl.class, Object.class, long.class)
189191
: null;
190192
MAPPED_MEMORY_UTILS_PROXY_CLASS = ReflectionUtil.lookupClass(true, "jdk.internal.access.foreign.MappedMemoryUtilsProxy");
193+
ABSTRACT_MEMORY_SEGMENT_IMPL_CLASS = ReflectionUtil.lookupClass(true, "jdk.internal.foreign.AbstractMemorySegmentImpl");
191194
}
192195

193196
protected List<ValueNode> scopedMemorySessions;
@@ -420,12 +423,16 @@ private static List<SessionCheck> getSessionArguments(ResolvedJavaMethod method,
420423
assert method != null;
421424
final ResolvedJavaType sessionType = ((AnalysisType) metaAccess.lookupJavaType(MemorySessionImpl.class)).getWrapped();
422425
assert sessionType != null;
426+
final ResolvedJavaType abstractSegmentImpl = ((AnalysisType) metaAccess.lookupJavaType(ABSTRACT_MEMORY_SEGMENT_IMPL_CLASS)).getWrapped();
427+
assert abstractSegmentImpl != null;
423428
final ResolvedJavaType baseType = ((AnalysisType) metaAccess.lookupJavaType(Object.class)).getWrapped();
424429
assert baseType != null;
425430
final ResolvedJavaType offsetType = ((AnalysisType) metaAccess.lookupJavaType(long.class)).getWrapped();
426431
assert offsetType != null;
427432
final ResolvedJavaType utilsType = ((AnalysisType) metaAccess.lookupJavaType(MAPPED_MEMORY_UTILS_PROXY_CLASS)).getWrapped();
428433
assert utilsType != null;
434+
final ResolvedJavaType classType = ((SubstitutionType) ((AnalysisType) metaAccess.lookupJavaType(Class.class)).getWrapped()).getOriginal();
435+
assert classType != null;
429436

430437
Parameter[] p = method.getParameters();
431438
if (!p[0].getType().equals(sessionType)) {
@@ -464,11 +471,43 @@ private static List<SessionCheck> getSessionArguments(ResolvedJavaMethod method,
464471
} else {
465472
// 1 session case
466473
ValueNode session = graph.getParameter(pIndex++);
467-
ValueNode base = graph.getParameter(pIndex++);
468-
ValueNode offset = graph.getParameter(pIndex++);
469-
SessionCheck check = new SessionCheck(session, base, offset);
470-
verifySession(sessionType, baseType, offsetType, check, metaAccess);
471-
return List.of(check);
474+
if (p[1].getType().equals(classType)) {
475+
// example with a vmClass -
476+
// storeIntoMemorySegmentScopedInternal(MemorySessionImpl session,
477+
// Class<? extends V> vmClass, Class<E> e, int length,V v,
478+
// AbstractMemorySegmentImpl msp, long offset,
479+
480+
/*
481+
* For all patterns involving a vmClass the following holds: session is always
482+
* p[0], and vmClass is always p[1]. However, in between we can have Class<E> e,
483+
* int length, V v, M m then msp, offset, M m, S s, offsetInRange etc.
484+
*
485+
* We always map AbstractMemorySegmentImpl msp to base and offset to offset
486+
* (which always comes after). There can be arguments after offset which we
487+
* ignore. And we skip all arguments between vmClass and msp. So any arg between
488+
* vmClass and msp can be skipped.
489+
*
490+
* If any of these invariants stops holding the verifySession call below will
491+
* fail hard and we will be noticed of new/changed API.
492+
*/
493+
while (!p[pIndex].getType().equals(abstractSegmentImpl)) {
494+
pIndex++;
495+
}
496+
497+
// use msp as base and offset as offset
498+
ValueNode base = graph.getParameter(pIndex++); // use msp
499+
ValueNode offset = graph.getParameter(pIndex++);
500+
501+
SessionCheck check = new SessionCheck(session, base, offset);
502+
verifySession(sessionType, baseType, offsetType, check, metaAccess);
503+
return List.of(check);
504+
} else {
505+
ValueNode base = graph.getParameter(pIndex++);
506+
ValueNode offset = graph.getParameter(pIndex++);
507+
SessionCheck check = new SessionCheck(session, base, offset);
508+
verifySession(sessionType, baseType, offsetType, check, metaAccess);
509+
return List.of(check);
510+
}
472511
}
473512
}
474513

0 commit comments

Comments
 (0)