Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions doc/jit-plan.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
From Cam's email on Mar 2025

[ ] Mixin vs Annotation — also: Exception
[X] Mixin vs Annotation — also: Exception
[ ] Service API review, also const
[ ] make/immutable review
[ ] Gold/types
[ ] mixin design!
[ ] AST vs byte code design
[-] Gold/types
[X] mixin design!
[X] AST vs byte code design
[ ] GC & RAM usage design
[ ] Fiber <-> virtual thread design
[ ] Future design
[ ] String design & review — graphemes, normalization
[X] String design & review — graphemes, normalization
[ ] Struct vs Object, also Public/RO references and +/- types/masking
[ ] Unions
[ ] Immutable Objects
[ ] Properties
[ ] Calling convention!!!
[ ] Property/Field layout
[X] Immutable Objects
[X] Properties
[X] Calling convention!!!
[X] Property/Field layout
[ ] Container design & lifecycle/masking
[ ] Bin code caching/storage/JIT/optJIT
[ ] Safepoints — how to include & what do they do?
[ ] CPU measure
[ ] Intrinsics — how to design "the divide"
[X] Intrinsics — how to design "the divide"
[ ] Service boundary design & automation
[ ] Class, Type, Generics
[ ] Specialization
[ ] default args
[X] default args
[x] Construction — 7 steps (BaseTemplate.Construct proceed)
[ ] Enum | Enumeration type design
[X] Enum | Enumeration type design
Review eg. Prev & Next
[ ] obj persistence (native optimization)
[ ] Container persistence (shelf)
Expand Down
47 changes: 47 additions & 0 deletions javatools/src/main/java/org/xvm/asm/MethodStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,53 @@ public void setConstructFinally(MethodStructure structFinally) {
m_idFinally = structFinally.getIdentityConstant();
}

/**
* @return true iff this constructor or a constructor it invokes has a finalizer
*/
public boolean hasConstructorFinalizers() {
assert isConstructor();
return hasConstructorFinalizers(new HashSet<>());
}

/**
* @return true iff this constructor or any constructor it invokes has a finalizer (recursively)
*/
private boolean hasConstructorFinalizers(Set<MethodConstant> setVisited) {
// constructor cycles are not expected; this guard is simply defensive
if (!setVisited.add(getIdentityConstant())) {
return false;
}

if (getConstructFinally() != null) {
return true;
}

if (hasCode()) {
Constant[] aconst = getLocalConstants();
for (Op op : getOps()) {
op = op.ensureOp();

switch (op.getOpCode()) {
case Op.OP_CONSTR_0, Op.OP_CONSTR_1, Op.OP_CONSTR_N, Op.OP_CONSTR_T:
int nCtorId = ((OpCallable) op).getFunctionId();
assert nCtorId <= Op.CONSTANT_OFFSET;

MethodConstant idCtor = (MethodConstant) aconst[Op.CONSTANT_OFFSET - nCtorId];
MethodStructure ctor = (MethodStructure) idCtor.getComponent();

if (ctor.hasConstructorFinalizers(setVisited)) {
return true;
}
break;

default:
break;
}
}
}
return false;
}

/**
* @return true iff this method has code
*/
Expand Down
15 changes: 13 additions & 2 deletions javatools/src/main/java/org/xvm/asm/OpCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,15 @@ public void registerConstants(ConstantRegistry registry) {
public String toString() {
return super.toString() + ' ' + getFunctionString() + '(' + getParamsString() + ") -> " + getReturnsString();
}

protected String getFunctionString() {
return Argument.toIdString(m_argFunction, m_nFunctionId);
}

protected String getParamsString() {
return "";
}

protected static String getParamsString(int[] anArgValue, Argument[] aArgValue) {
StringBuilder sb = new StringBuilder();
int cArgNums = anArgValue == null ? 0 : anArgValue.length;
Expand All @@ -171,6 +174,7 @@ protected static String getParamsString(int[] anArgValue, Argument[] aArgValue)
}
return sb.toString();
}

protected String getReturnsString() {
if (m_anRetValue != null || m_aArgReturn != null) {
// multi-return
Expand All @@ -194,6 +198,13 @@ protected String getReturnsString() {

// ----- helper methods ------------------------------------------------------------------------

/**
* @return the encoded function argument id
*/
public int getFunctionId() {
return m_nFunctionId;
}

/**
* This Op holds a constant for the constructor of a child of the compile-time parent.
* The run-time type of the parent could extend the compile-time type and that parent
Expand Down Expand Up @@ -824,7 +835,7 @@ protected int buildCall(BuildContext bctx, CodeBuilder code, int[] anArgValue) {

boolean fTuple = isTupleReturn();
if (fTuple) {
jmdCall = jmdCall.standardOnly();
jmdCall = jmdCall.asStandardOnly();
}

int[] anRet = isMultiReturn()
Expand Down Expand Up @@ -888,7 +899,7 @@ protected int buildCall(BuildContext bctx, CodeBuilder code, int[] anArgValue) {
}

if (isTupleReturn()) {
jmdCall = jmdCall.standardOnly();
jmdCall = jmdCall.asStandardOnly();
}

MethodTypeDesc mdCall;
Expand Down
30 changes: 15 additions & 15 deletions javatools/src/main/java/org/xvm/asm/OpInvocable.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,23 +492,17 @@ private void buildSingleInvoke(BuildContext bctx, CodeBuilder code, ClassDesc cd
call = bctx.builder.resolvePrivateDetachedCall(infoMethod, typeInvoke);
}

JitMethodDesc jmd;
if (call == null) {
jmd = infoMethod.getJitDesc(bctx.builder, typeInvoke);
} else {
jmd = call.jmd();
code.checkcast(call.receiverCD() == null ? call.owner() : call.receiverCD());
}

String methodName = infoMethod.ensureJitMethodName(bctx.typeSystem);
JitMethodDesc jmd = call == null
? infoMethod.getJitDesc(bctx.builder, typeInvoke)
: call.jmd();

if (isTupleReturn()) {
if (jmd.isPrimitivized() && fUnboxed) {
Builder.box(code, typeInvoke);
cdInvoke = bctx.builder.getCCDesc(typeInvoke);
fUnboxed = false;
}
jmd = jmd.standardOnly();
jmd = jmd.asStandardOnly();
}

boolean fOptimized = jmd.isOptimized;
Expand All @@ -521,11 +515,17 @@ private void buildSingleInvoke(BuildContext bctx, CodeBuilder code, ClassDesc cd
Builder.unbox(code, typeInvoke);
}

if (!isPropCall && (bodyHead.getIdentity().getNestedDepth() > 2 ||
infoMethod.getTypeInfo() == null)) {
// nested and private mixin methods absent from TypeInfo need to be built here;
// the second check is based on the synthetic info produced by computeMethodInfo()
bctx.buildMethod(methodName, bodyHead);
String methodName = infoMethod.ensureJitMethodName(bctx.typeSystem);
TypeInfo infoOwner = infoMethod.getTypeInfo();
if (!isPropCall) {
IdentityConstant idNamespace = bodyHead.getIdentity().getNamespace();
if (infoOwner == null ||
idNamespace.isNested() &&
!idNamespace.equals(infoOwner.getType().getDefiningConstant())) {
// direct members are assembled by their type's method loop; nested methods
// and methods absent from TypeInfo are assembled on demand
bctx.buildMethod(methodName, bodyHead);
}
}

MethodTypeDesc md;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public String getJitICName(TypeSystem ts) {
return m_constType.getJitICName(ts);
}

@Override
public String getJitImplName(TypeSystem ts) {
return m_constType.getJitImplName(ts);
}

// ----- Constant methods ----------------------------------------------------------------------

@Override
Expand Down
12 changes: 7 additions & 5 deletions javatools/src/main/java/org/xvm/asm/constants/ClassConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,15 @@ public boolean isClass() {

@Override
public TypeConstant getType() {
ClassStructure clz = (ClassStructure) getComponent();
ConstantPool pool = getConstantPool();
ClassStructure clz = (ClassStructure) getComponent();

return clz.isVirtualChild() ? getConstantPool().ensureVirtualChildTypeConstant(
// an inner class's outer is the containing class, not an intervening method or property
return clz.isVirtualChild() ? pool.ensureVirtualChildTypeConstant(
getParentConstant().getType(), getName())
: clz.isInnerChild() ? getConstantPool().ensureInnerChildTypeConstant(
getParentConstant().getType(), this)
: clz.isAnonInnerClass() ? getConstantPool().ensureAnonymousClassTypeConstant(
: clz.isInnerChild() ? pool.ensureInnerChildTypeConstant(
getParentConstant().getClassIdentity().getFormalType(), this)
: clz.isAnonInnerClass() ? pool.ensureAnonymousClassTypeConstant(
getParentConstant().getType(), this)
: super.getType();
}
Expand Down
Loading
Loading