Skip to content

Commit

Permalink
Pre-compute TypeMetadata for array element class.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmoresena committed Jul 22, 2024
1 parent 4b3f3ff commit 32e8a93
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private static Boolean IsFinalArrayType(JClassObject arrayClass)
if (dimension + 1 == arrayClass.ClassSignature.Length) return true;
IEnvironment env = arrayClass.Environment;
JClassObject elementClass = env.ClassFeature.GetClass(arrayClass.ClassSignature.AsSpan()[(dimension + 1)..^1]);
_ = env.ClassFeature.GetTypeMetadata(elementClass);
return elementClass.IsFinal;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ private static void FinalClassTest<TDataType>() where TDataType : IDataType<TDat
.CallPrimitiveFunction(Arg.Any<IFixedMemory>(), jClass, jClassClass, definition, false, []);
if (jClassElement is null) return;
env.ClassFeature.Received(count).GetClass(jClassElement.Name);
// To optimize JNI calls, element TypeMetadata should be pre-computed.
env.ClassFeature.Received(count).GetTypeMetadata(jClassElement);
// We are calling JClassObject.IsFinal which is always initialized when class is created from IDataType<T>
env.AccessFeature.Received(0)
.CallPrimitiveFunction(Arg.Any<IFixedMemory>(), jClassElement, jClassClass, definition, false, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private static JArrayObject CreateErrorArrayParameter(NativeInterfaceProxy proxy
{
proxyEnv.Received(1).GetObjectRefType(localRef);
proxyEnv.Received(1).GetObjectClass(localRef);
proxyEnv.Received(initial ? 2 : 0).FindClass(Arg.Any<ReadOnlyValPtr<Byte>>());
proxyEnv.Received(initial ? 1 : 0).FindClass(Arg.Any<ReadOnlyValPtr<Byte>>());
proxyEnv.Received(initial ? 1 : 0).GetSuperclass(elementClassRef);
proxyEnv.Received(1).GetStringUtfLength(strRef0);
proxyEnv.Received(initial ? 1 : 0).GetStringUtfLength(strRef1);
Expand Down Expand Up @@ -378,7 +378,7 @@ private static JArrayObject CreateInterfaceArrayParameter(NativeInterfaceProxy p
{
proxyEnv.Received(1).GetObjectRefType(localRef);
proxyEnv.Received(1).GetObjectClass(localRef);
proxyEnv.Received(initial ? 2 : 0).FindClass(Arg.Any<ReadOnlyValPtr<Byte>>());
proxyEnv.Received(initial ? 1 : 0).FindClass(Arg.Any<ReadOnlyValPtr<Byte>>());
proxyEnv.Received(0).GetSuperclass(elementClassRef);
proxyEnv.Received(initial ? 1 : 0).CallObjectMethod(elementClassRef.Value,
proxyEnv.VirtualMachine.ClassGetInterfacesMethodId,
Expand Down Expand Up @@ -480,7 +480,7 @@ private static JArrayObject CreateEnumArrayParameter(NativeInterfaceProxy proxyE
{
proxyEnv.Received(1).GetObjectRefType(localRef);
proxyEnv.Received(1).GetObjectClass(localRef);
proxyEnv.Received(initial ? 2 : 0).FindClass(Arg.Any<ReadOnlyValPtr<Byte>>());
proxyEnv.Received(initial ? 1 : 0).FindClass(Arg.Any<ReadOnlyValPtr<Byte>>());
proxyEnv.Received(initial ? 1 : 0).GetSuperclass(elementClassRef);
proxyEnv.Received(1).GetStringUtfLength(strRef0);
proxyEnv.Received(initial ? 1 : 0).GetStringUtfLength(strRef1);
Expand Down

0 comments on commit 32e8a93

Please sign in to comment.