Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Static Initializer out of Module Init path #465

Merged
merged 3 commits into from
Jan 6, 2024
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
2 changes: 1 addition & 1 deletion openjdk
2 changes: 1 addition & 1 deletion src/IKVM.Runtime/Accessors/AccessorRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal struct AccessorRef<T> where T : Accessor
/// <summary>
/// Gets the accessor value.
/// </summary>
public T Value => JVM.BaseAccessors.Get(ref accessor);
public T Value => JVM.Internal.BaseAccessors.Get(ref accessor);

}

Expand Down
4 changes: 2 additions & 2 deletions src/IKVM.Runtime/ByteCodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static class ByteCodeHelper

static ObjectAccessor objectAccessor;

static ObjectAccessor ObjectAccessor => JVM.BaseAccessors.Get(ref objectAccessor);
static ObjectAccessor ObjectAccessor => JVM.Internal.BaseAccessors.Get(ref objectAccessor);

#endif

Expand Down Expand Up @@ -209,7 +209,7 @@ static RuntimeJavaType LoadTypeWrapper(string clazz, [email protected] cal
if (loader != null)
{
ClassLoaderAccessor cla = null;
JVM.BaseAccessors.Get(ref cla);
JVM.Internal.BaseAccessors.Get(ref cla);
cla.InvokeCheckPackageAccess(loader, wrapper.ClassObject, callerId.getCallerClass().pd);
}

Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.Runtime/ClassLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class ClassLiteral<T>
static ClassAccessor classAccessor;
static object value;

static ClassAccessor ClassAccessor => JVM.BaseAccessors.Get(ref classAccessor);
static ClassAccessor ClassAccessor => JVM.Internal.BaseAccessors.Get(ref classAccessor);

/// <summary>
/// Gets the class literal value, caching the result.
Expand Down
61 changes: 61 additions & 0 deletions src/IKVM.Runtime/JVM.Internal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Diagnostics;
using System.Security;
using System.Text;
using System.Threading;

using IKVM.Runtime.Accessors;
using IKVM.Runtime.Accessors.Java.Lang;
using IKVM.Runtime.Vfs;

#if IMPORTER || EXPORTER
using IKVM.Reflection;
using Type = IKVM.Reflection.Type;
#else
#endif

#if IMPORTER
using IKVM.Tools.Importer;
#endif

namespace IKVM.Runtime
{

static partial class JVM
{

/// <summary>
/// Internal services of the JVM.
/// </summary>
/// <remarks>
/// JVM.Internal exists so that static initialization of JVM does not cause initialization of internal state.
/// </remarks>
internal static class Internal
{

internal const string JarClassList = "--ikvm-classes--/";

#if FIRST_PASS == false && IMPORTER == false && EXPORTER == false

internal static readonly RuntimeContext context = new RuntimeContext(new RuntimeContextOptions(), new Resolver(), false);
internal static readonly VfsTable vfs = VfsTable.BuildDefaultTable(new VfsRuntimeContext(context), Properties.HomePath);
internal static readonly Lazy<object> systemThreadGroup = new Lazy<object>(() => ThreadGroupAccessor.Init());
internal static readonly Lazy<object> mainThreadGroup = new Lazy<object>(() => ThreadGroupAccessor.Init(null, SystemThreadGroup, "main"));

static AccessorCache baseAccessors;
static ThreadGroupAccessor threadGroupAccessor;
static SystemAccessor systemAccessor;

internal static AccessorCache BaseAccessors => AccessorCache.Get(ref baseAccessors, context.Resolver.ResolveBaseAssembly());

internal static ThreadGroupAccessor ThreadGroupAccessor => BaseAccessors.Get(ref threadGroupAccessor);

internal static SystemAccessor SystemAccessor => BaseAccessors.Get(ref systemAccessor);

#endif

}

}

}
Loading