Skip to content

Commit

Permalink
Replace IssueMessage with various versions of Report. It's still a bi…
Browse files Browse the repository at this point in the history
…t weird how there are special calls for CompilerClassLoader. This is because its the only thing that holds the options.

Problem is not all Types are part of a ClassLoader. Some are shared between class loaders. Maybe it makes sense to have some fundamental class loader for them.
  • Loading branch information
wasabii committed Aug 22, 2024
1 parent d2bf075 commit 8f281a5
Show file tree
Hide file tree
Showing 33 changed files with 348 additions and 984 deletions.
6 changes: 6 additions & 0 deletions src/IKVM.CoreLib/Diagnostics/DiagnosticId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ record struct DiagnosticId(int Value)

public static implicit operator DiagnosticId(int id) => new DiagnosticId(id);

/// <inheritdoc />
public override string ToString()
{
return Value.ToString();
}

}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using IKVM.CoreLib.Diagnostics;

namespace IKVM.Runtime
namespace IKVM.CoreLib.Diagnostics
{

/// <summary>
/// Accepts a <see cref="DiagnosticEvent"> and routes it to the appropriate source.
/// </summary>
internal interface IDiagnosticHandler
interface IDiagnosticHandler
{

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.Runtime-ref/IKVM.Runtime-ref.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IKVM.CoreLib\IKVM.CoreLib.csproj" Private="False" PrivateAssets="All" />
<ProjectReference Include="..\IKVM.CoreLib\IKVM.CoreLib.csproj" />
<ProjectReference Include="..\IKVM.Java-ref\IKVM.Java-ref.csproj" Private="False" PrivateAssets="All" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion src/IKVM.Runtime/AttributeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Jeroen Frijters
using System.Runtime.CompilerServices;

using IKVM.Attributes;
using IKVM.CoreLib.Diagnostics;
using IKVM.ByteCode.Buffers;
using IKVM.ByteCode.Decoding;
using IKVM.ByteCode.Encoding;
Expand Down Expand Up @@ -199,7 +200,7 @@ object ParseValue(RuntimeClassLoader loader, RuntimeJavaType tw, string val)
}
else if (tw.IsUnloadable)
{
throw new FatalCompilerErrorException(Message.MapFileTypeNotFound, tw.Name);
throw new FatalCompilerErrorException(Diagnostic.MapFileTypeNotFound.Event([tw.Name]));
}
else if (tw.TypeAsTBD.IsEnum)
{
Expand Down
4 changes: 2 additions & 2 deletions src/IKVM.Runtime/ByteCodeHelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Jeroen Frijters
*/
using System;

using IKVM.Runtime;
using IKVM.CoreLib.Diagnostics;

#if IMPORTER
using IKVM.Reflection;
Expand Down Expand Up @@ -179,7 +179,7 @@ static MethodInfo GetHelper(Type type, string method, Type[] parameters)
var mi = parameters == null ? type.GetMethod(method) : type.GetMethod(method, parameters);
if (mi == null)
#if IMPORTER
throw new FatalCompilerErrorException(Message.RuntimeMethodMissing, method);
throw new FatalCompilerErrorException(Diagnostic.RuntimeMethodMissing.Event([method]));
#else
throw new InternalException("Missing ByteCodeHelper method in runtime.");
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/IKVM.Runtime/ClassFile.Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Jeroen Frijters
using IKVM.Attributes;
using IKVM.ByteCode;
using IKVM.ByteCode.Decoding;
using IKVM.CoreLib.Diagnostics;


#if IMPORTER
using IKVM.Tools.Importer;
Expand Down Expand Up @@ -181,7 +183,7 @@ internal Method(ClassFile classFile, string[] utf8_cp, ClassFileParseOptions opt
{
if (classFile.IsInterface)
{
classFile.context.StaticCompiler.IssueMessage(Message.InterfaceMethodCantBeInternal, classFile.Name, Name, Signature);
classFile.context.Report(Diagnostic.InterfaceMethodCantBeInternal.Event([classFile.Name, Name, Signature]));
}
else
{
Expand All @@ -206,7 +208,7 @@ internal Method(ClassFile classFile, string[] utf8_cp, ClassFileParseOptions opt
{
if (classFile.IsInterface || IsConstructor || IsClassInitializer || IsPrivate || IsStatic == false)
{
classFile.context.StaticCompiler.IssueMessage(Message.ModuleInitializerMethodRequirements, classFile.Name, Name, Signature);
classFile.context.Report(Diagnostic.ModuleInitializerMethodRequirements.Event([classFile.Name, Name, Signature]));
}
else
{
Expand Down
45 changes: 45 additions & 0 deletions src/IKVM.Runtime/JVM.Diagnostics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using IKVM.CoreLib.Diagnostics;

namespace IKVM.Runtime
{

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

static partial class JVM
{

/// <summary>
/// Handles diagnostic events during runtime.
/// </summary>
class DiagnosticHandler : IDiagnosticHandler
{

public void Report(in DiagnosticEvent evnt)
{
switch (evnt.Diagnostic.Level)
{
case DiagnosticLevel.Trace:
break;
case DiagnosticLevel.Informational:
break;
case DiagnosticLevel.Warning:
break;
case DiagnosticLevel.Error:
break;
case DiagnosticLevel.Fatal:
break;
}
}

}

/// <summary>
/// Gets the JVM diagnostic handler.
/// </summary>
static IDiagnosticHandler Diagnostics { get; } = new DiagnosticHandler();

}

#endif

}
2 changes: 1 addition & 1 deletion src/IKVM.Runtime/JVM.Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static class Internal
#if FIRST_PASS == false && IMPORTER == false && EXPORTER == false

internal static readonly RuntimeContextOptions contextOptions = new RuntimeContextOptions();
internal static readonly RuntimeContext context = new RuntimeContext(contextOptions, new Resolver(), false);
internal static readonly RuntimeContext context = new RuntimeContext(contextOptions, Diagnostics, 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"));
Expand Down
3 changes: 2 additions & 1 deletion src/IKVM.Runtime/LambdaMetafactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Jeroen Frijters
using System.Diagnostics;

using IKVM.ByteCode;
using IKVM.CoreLib.Diagnostics;

#if IMPORTER
using IKVM.Reflection;
Expand Down Expand Up @@ -60,7 +61,7 @@ internal static bool Emit(RuntimeByteCodeJavaType.FinishContext context, ClassFi
#if IMPORTER
if (context.TypeWrapper.GetClassLoader().DisableDynamicBinding)
{
context.Context.StaticCompiler.IssueMessage(Message.UnableToCreateLambdaFactory);
context.Context.Report(Diagnostic.UnableToCreateLambdaFactory.Event([]));
}
#endif
return false;
Expand Down
26 changes: 14 additions & 12 deletions src/IKVM.Runtime/MethodAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Jeroen Frijters
using System.Diagnostics;

using IKVM.ByteCode;
using IKVM.CoreLib.Diagnostics;


#if IMPORTER
using IKVM.Tools.Importer;
Expand Down Expand Up @@ -2484,38 +2486,38 @@ private void SetHardError(RuntimeClassLoader classLoader, ref ClassFile.Method.I
{
string text = string.Format(message, args);
#if IMPORTER
Message msg;
Diagnostic msg;
switch (hardError)
{
case HardError.NoClassDefFoundError:
msg = Message.EmittedNoClassDefFoundError;
msg = Diagnostic.EmittedNoClassDefFoundError;
break;
case HardError.IllegalAccessError:
msg = Message.EmittedIllegalAccessError;
msg = Diagnostic.EmittedIllegalAccessError;
break;
case HardError.InstantiationError:
msg = Message.EmittedIllegalAccessError;
msg = Diagnostic.EmittedIllegalAccessError;
break;
case HardError.IncompatibleClassChangeError:
case HardError.IllegalAccessException:
msg = Message.EmittedIncompatibleClassChangeError;
msg = Diagnostic.EmittedIncompatibleClassChangeError;
break;
case HardError.NoSuchFieldError:
msg = Message.EmittedNoSuchFieldError;
msg = Diagnostic.EmittedNoSuchFieldError;
break;
case HardError.AbstractMethodError:
msg = Message.EmittedAbstractMethodError;
msg = Diagnostic.EmittedAbstractMethodError;
break;
case HardError.NoSuchMethodError:
msg = Message.EmittedNoSuchMethodError;
msg = Diagnostic.EmittedNoSuchMethodError;
break;
case HardError.LinkageError:
msg = Message.EmittedLinkageError;
msg = Diagnostic.EmittedLinkageError;
break;
default:
throw new InvalidOperationException();
}
classLoader.IssueMessage(msg, classFile.Name + "." + method.Name + method.Signature, text);
classLoader.Report(msg.Event([classFile.Name + "." + method.Name + method.Signature, text]));
#endif
instruction.SetHardError(hardError, AllocErrorMessage(text));
}
Expand Down Expand Up @@ -2868,7 +2870,7 @@ private string CheckLoaderConstraints(ClassFile.ConstantPoolItemMI cpi, RuntimeJ
#if NETFRAMEWORK
if (cpi.GetRetType() != mw.ReturnType && !cpi.GetRetType().IsUnloadable && !mw.ReturnType.IsUnloadable)
#else
if (cpi.GetRetType() != mw.ReturnType && cpi.GetRetType().Name != mw.ReturnType.Name && !cpi.GetRetType().IsUnloadable && !mw.ReturnType.IsUnloadable)
if (cpi.GetRetType() != mw.ReturnType && cpi.GetRetType().Name != mw.ReturnType.Name && !cpi.GetRetType().IsUnloadable && !mw.ReturnType.IsUnloadable)
#endif
{
#if IMPORTER
Expand All @@ -2883,7 +2885,7 @@ private string CheckLoaderConstraints(ClassFile.ConstantPoolItemMI cpi, RuntimeJ
#if NETFRAMEWORK
if (here[i] != there[i] && !here[i].IsUnloadable && !there[i].IsUnloadable)
#else
if (here[i] != there[i] && here[i].Name != there[i].Name && !here[i].IsUnloadable && !there[i].IsUnloadable)
if (here[i] != there[i] && here[i].Name != there[i].Name && !here[i].IsUnloadable && !there[i].IsUnloadable)
#endif
{
#if IMPORTER
Expand Down
6 changes: 3 additions & 3 deletions src/IKVM.Runtime/RuntimeAssemblyClassLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Jeroen Frijters
using System.Diagnostics;
using System.Threading;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;

using IKVM.CoreLib.Diagnostics;
using IKVM.Attributes;
using IKVM.Runtime.Syntax;

using System.Runtime.CompilerServices;


#if IMPORTER || EXPORTER
using IKVM.Reflection;
Expand Down Expand Up @@ -715,7 +715,7 @@ internal virtual RuntimeJavaType GetJavaTypeFromAssemblyType(Type type)
if (javaType.TypeAsTBD != type && (!javaType.IsRemapped || javaType.TypeAsBaseType != type))
{
#if IMPORTER
throw new FatalCompilerErrorException(Message.AssemblyContainsDuplicateClassNames, type.FullName, javaType.TypeAsTBD.FullName, javaType.Name, type.Assembly.FullName);
throw new FatalCompilerErrorException(Diagnostic.AssemblyContainsDuplicateClassNames.Event([type.FullName, javaType.TypeAsTBD.FullName, javaType.Name, type.Assembly.FullName]));
#else
throw new InternalException($"\nType \"{type.FullName}\" and \"{javaType.TypeAsTBD.FullName}\" both map to the same name \"{javaType.Name}\".");
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/IKVM.Runtime/RuntimeByteCodeJavaType.JavaTypeImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Jeroen Frijters
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Collections.Concurrent;

using IKVM.Attributes;
using System.Collections.Concurrent;

using IKVM.CoreLib.Diagnostics;

#if IMPORTER
using IKVM.Reflection;
Expand Down Expand Up @@ -225,7 +227,7 @@ bool SupportsCallerID(ClassFile.Method method)
{
// If we end up here, we either have to add support or add them to the white-list in the above clause
// to allow them to fall back to dynamic stack walking.
wrapper.Context.StaticCompiler.IssueMessage(Message.CallerSensitiveOnUnsupportedMethod, classFile.Name, method.Name, method.Signature);
wrapper.Context.Report(Diagnostic.CallerSensitiveOnUnsupportedMethod.Event([classFile.Name, method.Name, method.Signature]));
return false;
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/IKVM.Runtime/RuntimeByteCodeJavaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Jeroen Frijters
using System.Diagnostics;

using IKVM.Attributes;
using IKVM.CoreLib.Diagnostics;


#if IMPORTER
using IKVM.Reflection;
Expand Down Expand Up @@ -97,10 +99,10 @@ private static void CheckMissing(RuntimeJavaType prev, RuntimeJavaType tw)
Type mt = ReflectUtil.GetMissingType(missing.MissingType);
if (mt.Assembly.__IsMissing)
{
throw new FatalCompilerErrorException(Message.MissingBaseTypeReference, mt.FullName, mt.Assembly.FullName);
throw new FatalCompilerErrorException(Diagnostic.MissingBaseTypeReference.Event([mt.FullName, mt.Assembly.FullName]));
}
throw new FatalCompilerErrorException(Message.MissingBaseType, mt.FullName, mt.Assembly.FullName,
prev.TypeAsBaseType.FullName, prev.TypeAsBaseType.Module.Name);

throw new FatalCompilerErrorException(Diagnostic.MissingBaseType.Event([mt.FullName, mt.Assembly.FullName, prev.TypeAsBaseType.FullName, prev.TypeAsBaseType.Module.Name]));
}
foreach (RuntimeJavaType iface in tw.Interfaces)
{
Expand Down Expand Up @@ -1064,10 +1066,10 @@ internal void EmitLevel4Warning(HardError error, string message)
switch (error)
{
case HardError.AbstractMethodError:
GetClassLoader().IssueMessage(Message.EmittedAbstractMethodError, this.Name, message);
GetClassLoader().Report(Diagnostic.EmittedAbstractMethodError.Event([this.Name, message]));
break;
case HardError.IncompatibleClassChangeError:
GetClassLoader().IssueMessage(Message.EmittedIncompatibleClassChangeError, this.Name, message);
GetClassLoader().Report(Diagnostic.EmittedIncompatibleClassChangeError.Event([this.Name, message]));
break;
default:
throw new InvalidOperationException();
Expand Down
7 changes: 5 additions & 2 deletions src/IKVM.Runtime/RuntimeByteCodePropertyJavaField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ Jeroen Frijters
*/
using System;

using IKVM.CoreLib.Diagnostics;

#if IMPORTER || EXPORTER
using IKVM.Reflection;
using IKVM.Reflection.Emit;

using Type = IKVM.Reflection.Type;

#else
using System.Reflection;
using System.Reflection.Emit;
Expand Down Expand Up @@ -141,7 +144,7 @@ protected override void EmitGetImpl(CodeEmitter ilgen)
internal static void EmitThrowNoSuchMethodErrorForGetter(CodeEmitter ilgen, RuntimeJavaType type, RuntimeJavaMember member)
{
#if IMPORTER
type.Context.StaticCompiler.IssueMessage(Message.EmittedNoSuchMethodError, "<unknown>", member.DeclaringType.Name + "." + member.Name + member.Signature);
type.Context.StaticCompiler.Report(Diagnostic.EmittedNoSuchMethodError.Event(["<unknown>", member.DeclaringType.Name + "." + member.Name + member.Signature]));
#endif
// HACK the branch around the throw is to keep the verifier happy
CodeEmitterLabel label = ilgen.DefineLabel();
Expand Down Expand Up @@ -186,7 +189,7 @@ protected override void EmitSetImpl(CodeEmitter ilgen)
internal static void EmitThrowNoSuchMethodErrorForSetter(CodeEmitter ilgen, RuntimeJavaMember member)
{
#if IMPORTER
member.DeclaringType.Context.StaticCompiler.IssueMessage(Message.EmittedNoSuchMethodError, "<unknown>", member.DeclaringType.Name + "." + member.Name + member.Signature);
member.DeclaringType.Context.Report(Diagnostic.EmittedNoSuchMethodError.Event(["<unknown>", member.DeclaringType.Name + "." + member.Name + member.Signature]));
#endif
// HACK the branch around the throw is to keep the verifier happy
CodeEmitterLabel label = ilgen.DefineLabel();
Expand Down
Loading

0 comments on commit 8f281a5

Please sign in to comment.