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

IKVM.Reflection ILGenerator/PDB Rewrite #478

Merged
merged 40 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ea8a1da
In progress.
wasabii Jan 20, 2024
32c7b8a
Patch up PDB stuff.
wasabii Jan 24, 2024
fadebbe
Fix up local variables.
wasabii Jan 24, 2024
0488a97
Fix docs.
wasabii Jan 24, 2024
a754c2e
Comment.
wasabii Jan 24, 2024
572bc74
Serialize FieldSignature initially so TypeRefs are created.
wasabii Jan 24, 2024
24f8e76
Fixes
wasabii Jan 24, 2024
06530a7
Fix ILGenerator sbyte overload for br.s instruction.
wasabii Jan 25, 2024
5b129fc
Missed these.
wasabii Jan 25, 2024
1117607
Load arguments.
wasabii Jan 26, 2024
ac2ef55
Initialize JVM before executing show version, since ShowVersion requi…
wasabii Jan 26, 2024
dda6d24
Merge branch 'develop' into ilgen2
wasabii Feb 6, 2024
567957d
Remove debug tables.
wasabii Feb 6, 2024
96c28b1
Merge branch 'ilgen2' of https://github.com/ikvmnet/ikvm into ilgen2
wasabii Feb 6, 2024
cfb0aaf
InitialDocument support for SequencePointEncoder. Take first document…
wasabii Feb 6, 2024
02881c8
Setup document right.
wasabii Feb 6, 2024
4164daf
Change SequencePointEncoer back. But don't add local signature. This …
wasabii Feb 7, 2024
043e02b
Merge branch 'develop' into ilgen2
wasabii Feb 7, 2024
60d0dd8
Merge branch 'develop' into ilgen2
wasabii Feb 7, 2024
e590a0b
For now, lets disable sequence points and see if we can get a clean b…
wasabii Feb 8, 2024
eb5d3f2
Remove verify base lib tests.
wasabii Feb 8, 2024
7d97817
Add scopes back. Do they break?
wasabii Feb 8, 2024
b0424e6
Update Buildalyzer. Required for working directory change. Apparently…
wasabii Feb 9, 2024
cc1071a
Enable debug symbols.
wasabii Feb 10, 2024
7f6bc1a
Minor code cleanup.
wasabii Feb 10, 2024
87fd06c
Enable sequence points again. At least we know where the issue is.
wasabii Feb 10, 2024
26d2eb7
Change TFM.
wasabii Feb 10, 2024
9bff816
Merge branch 'develop' into ilgen2
wasabii Feb 12, 2024
9519b1d
Merged.
wasabii Feb 12, 2024
f5da6ae
Emit IgnoreSymbolStoreSequencePoints.
wasabii Feb 12, 2024
f6d650a
Merge branch 'ilgen2' of https://github.com/ikvmnet/ikvm into ilgen2
wasabii Feb 12, 2024
f9a3e0f
Merge branch 'develop' into ilgen2
wasabii Feb 12, 2024
691bcfb
Merge branch 'develop' into ilgen2
wasabii Feb 12, 2024
4d25458
Resolve type through ResolveCore.
wasabii Feb 12, 2024
baeaebe
Merge branch 'ilgen2' of https://github.com/ikvmnet/ikvm into ilgen2
wasabii Feb 12, 2024
2ac466b
Merge branch 'develop' into ilgen2
wasabii Feb 13, 2024
21554b8
Disable code coverage to see if it fixes OOM.
wasabii Feb 14, 2024
ebf6c35
Clean.
wasabii Feb 15, 2024
e4e5a69
Fix exception handling
wasabii Feb 21, 2024
4b06d88
Update ReflectionFactory.cs
wasabii Feb 21, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/IKVM.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ jobs:
"-v:diag",
"--results-directory", "TestResults",
"--logger:console;verbosity=diag",
"--logger:trx",
"--collect", "Code Coverage"
"--logger:trx"
# "--collect", "Code Coverage"
)

$runsettings = $(gi .\tests\$tst\$tfm\*.runsettings)
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
<Import Project="targets\ClangProjectReference.targets" />
<Import Project="targets\DotNetOSXCodeSign.targets"/>

<PropertyGroup>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == 'win7-x86' ">win-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == 'win7-x64' ">win-x64</RuntimeIdentifier>
<Prefer32Bit Condition=" '$(RuntimeIdentifier)' == 'win-x86' ">true</Prefer32Bit>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The output assembly will be generated as part of your project's build process an
<Sources>MyClass.java;YourClass.java</Sources>
<References>SomeExternalDependency.jar;SomeOtherExternalDependency.jar</References>
<Aliases>MyAssemblyAlias;helloworld2_0</Aliases>
<Debug>true</Debug>
<Debug>portable</Debug>
</IkvmReference>
</ItemGroup>
```
Expand All @@ -139,7 +139,7 @@ The following values can be used as either an attribute or a nested element of `
| `Compile` | A semi-colon separated list of Java class path items to compile into the assembly. By default this value is the `Identity` of the item, if the identity of the item is an existing JAR file or directory (not yet supported). MSBuild globs are supported to reference multiple JAR or .class files. |
| `Sources` | A semi-colon separated list of Java source files to use during documentation generation. (not yet supported) |
| `References` | Optional semi-colon separated list of other `IkvmReference` identity values to specify as a reference to the current one. For example, if `foo.jar` depends on `bar.jar`, include both as `IkvmReference` items, but specify the identity of `bar.jar` on the `References` metadata of `foo.jar`. |
| `Debug` | Optional boolean indicating whether to generate debug symbols. By default this is determined based on the `<DebugType>` and `<DebugSymbols>` properties of the project. Only full debug symbols are currently supported. |
| `Debug` | Optional value indicating how to generate debug symbols. By default this is determined based on the `<DebugType>` properties of the project. Only full debug symbols are currently supported. |
| `Aliases` | A semi-colon separated list of aliases that can be used to reference the assembly in `References`. |
| `ClassLoader` | A fully qualified classs name of the custom ClassLoader implementation to use as a delegation parent. Examples include `ikvm.runtime.AppDomainAssemblyClassLoader` and `ikvm.runtime.ClassPathAssemblyClassLoader`. |
| All other metadata supported on the [`Reference`](https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items#reference) MSBuild item group definition. | |
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.ConsoleApp/IKVM.ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net481;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net481;</TargetFrameworks>
<LangVersion>11</LangVersion>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
Expand Down
7 changes: 1 addition & 6 deletions src/IKVM.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;

namespace IKVM.ConsoleApp
{
Expand All @@ -13,7 +14,6 @@ public static void Main(string[] args)
public static void Foo()
{
new Bar();
Environment.Exit(0);
}

class Bar
Expand All @@ -25,11 +25,6 @@ public Bar()
System.Console.WriteLine(java.net.InetAddress.getLocalHost().getHostName());
}

~Bar()
{

}

}

}
Expand Down
16 changes: 16 additions & 0 deletions src/IKVM.Java.Tests/java/lang/ThreadTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ikvm.tests.java.java.lang;

import java.lang.*;
import java.util.*;

@cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute.Annotation()
public class ThreadTests {

@cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation()
public void canPrintStackTrace() throws Throwable {
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
System.out.println(ste + "\n");
}
}

}
35 changes: 27 additions & 8 deletions src/IKVM.Java/map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@
<field name="suppressedExceptions" sig="Ljava.util.List;" />
<clinit>
<body>
<call type="IKVM.Runtime.ExceptionHelper" name="GetPersistentFields" sig="()[Ljava.io.ObjectStreamField;" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetPersistentFields" sig="()[Ljava.lang.Object;" />
<castclass class="[Ljava.io.ObjectStreamField;" />
<stsfld class="java.lang.Throwable" name="serialPersistentFields" sig="[Ljava.io.ObjectStreamField;" />
<ldc_i4_0 />
<newarr sig="Ljava.lang.StackTraceElement;" />
Expand Down Expand Up @@ -1010,7 +1011,7 @@
<body>
<ldarg_0 />
<ldarg_1 />
<call type="IKVM.Runtime.ExceptionHelper" name="ReadObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectInputStream;)V" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="ReadObject" sig="(Ljava.lang.Throwable;Ljava.lang.Object;)V" />
<ret />
</body>
</method>
Expand All @@ -1019,7 +1020,7 @@
<body>
<ldarg_0 />
<ldarg_1 />
<call type="IKVM.Runtime.ExceptionHelper" name="WriteObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectOutputStream;)V" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="WriteObject" sig="(Ljava.lang.Throwable;Ljava.lang.Object;)V" />
<ret />
</body>
</method>
Expand Down Expand Up @@ -1341,18 +1342,29 @@
<method name="getStackTrace" sig="()[Ljava.lang.StackTraceElement;" modifiers="public">
<body>
<ldarg_0 />
<call type="IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<callvirt type="System.Array" name="Clone" sig="()Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<ret />
</body>
</method>
<method name="getOurStackTrace" sig="()[Ljava.lang.StackTraceElement;" modifiers="private">
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;" />
<body>
<ldarg_0 />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<ret />
</body>
</method>
<method name="setStackTrace" sig="([Ljava.lang.StackTraceElement;)V" modifiers="public">
<parameter name="stackTrace" />
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="SetStackTrace" sig="(Ljava.lang.Throwable;[Ljava.lang.StackTraceElement;)V" />
<body>
<ldarg_0 />
<ldarg_1 />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="SetStackTrace" sig="(Ljava.lang.Throwable;[Ljava.lang.Object;)V" />
<ret/>
</body>
</method>
<method name="toString" sig="()Ljava.lang.String;" modifiers="public">
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="ToString" sig="(Ljava.lang.Throwable;)Ljava.lang.String;" />
Expand Down Expand Up @@ -1398,14 +1410,21 @@
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="GetStackTraceDepth" sig="(Ljava.lang.Throwable;)I" />
</method>
<method name="getStackTraceElement" sig="(I)Ljava.lang.StackTraceElement;" modifiers="">
<redirect class="cli.IKVM.Runtime.ExceptionHelper" name="GetStackTraceElement" sig="(Ljava.lang.Throwable;I)Ljava.lang.StackTraceElement;" />
<body>
<ldarg_0 />
<ldarg_1 />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetStackTraceElement" sig="(Ljava.lang.Throwable;I)Ljava.lang.Object;" />
<castclass class="java.lang.StackTraceElement" />
<ret />
</body>
</method>
</class>
<class name="java.lang.ThrowableHelper">
<method name="getOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;">
<body>
<ldarg_0 />
<call type="IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.StackTraceElement;" />
<call class="cli.IKVM.Runtime.ExceptionHelper" name="GetOurStackTrace" sig="(Ljava.lang.Throwable;)[Ljava.lang.Object;" />
<castclass class="[Ljava.lang.StackTraceElement;" />
<ret />
</body>
</method>
Expand Down
19 changes: 11 additions & 8 deletions src/IKVM.MSBuild.Tasks/IkvmCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class IkvmCompiler : IkvmToolExecTask

public bool CompressResources { get; set; }

public bool Debug { get; set; }
public string Debug { get; set; }

public bool NoAutoSerialization { get; set; }

Expand Down Expand Up @@ -241,12 +241,6 @@ public override bool Execute()

protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter writer, CancellationToken cancellationToken)
{
if (Debug && RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false)
{
Log.LogWarning("Emitting debug symbols from ikvmc is not supported on platforms other than Windows. Continuing without.");
Debug = false;
}

var options = new IkvmImporterOptions();
options.ResponseFile = ResponseFile;
options.Output = Output;
Expand Down Expand Up @@ -302,7 +296,16 @@ protected override async Task<bool> ExecuteAsync(IkvmToolTaskDiagnosticWriter wr
options.ExternalResources.Add(new IkvmImporterExternalResourceItem(resource.ItemSpec, resource.GetMetadata("ResourcePath")));

options.CompressResources = CompressResources;
options.Debug = Debug;

options.Debug = Debug?.ToLower() switch
{
"none" or "" or null => IkvmImporterDebugMode.None,
"portable" => IkvmImporterDebugMode.Portable,
"full" or "pdbonly" => IkvmImporterDebugMode.Full,
"embedded" => IkvmImporterDebugMode.Embedded,
_ => throw new NotImplementedException($"Unknown Debug option '{Debug}'.")
};

options.NoAutoSerialization = NoAutoSerialization;
options.NoGlobbing = NoGlobbing;
options.NoJNI = NoJNI;
Expand Down
36 changes: 33 additions & 3 deletions src/IKVM.MSBuild.Tasks/IkvmReferenceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IkvmReferenceItem[] Import(IEnumerable<ITaskItem> items)
item.References = ResolveReferences(map, item, item.Item.GetMetadata(IkvmReferenceItemMetadata.References)).ToList();
item.ClassLoader = item.Item.GetMetadata(IkvmReferenceItemMetadata.ClassLoader);
item.ResolvedReferences = item.Item.GetMetadata(IkvmReferenceItemMetadata.ResolvedReferences)?.Split(IkvmReferenceItemMetadata.PropertySeperatorCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
item.Debug = string.Equals(item.Item.GetMetadata(IkvmReferenceItemMetadata.Debug), "true", StringComparison.OrdinalIgnoreCase);
item.Debug = ParseDebug(item.Item.GetMetadata(IkvmReferenceItemMetadata.Debug));
item.KeyFile = item.Item.GetMetadata(IkvmReferenceItemMetadata.KeyFile);
item.DelaySign = string.Equals(item.Item.GetMetadata(IkvmReferenceItemMetadata.DelaySign), "true", StringComparison.OrdinalIgnoreCase);
item.Aliases = item.Item.GetMetadata(IkvmReferenceItemMetadata.Aliases);
Expand All @@ -79,6 +79,21 @@ public static IkvmReferenceItem[] Import(IEnumerable<ITaskItem> items)
return map.Values.ToArray();
}

/// <summary>
/// Parses the debug metadata value into the enum.
/// </summary>
/// <param name="debug"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
static IkvmReferenceItemDebug ParseDebug(string debug) => debug?.ToLower() switch
{
"none" or "false" or "" or null => IkvmReferenceItemDebug.None,
"full" or "true" => IkvmReferenceItemDebug.Full,
"portable" => IkvmReferenceItemDebug.Portable,
"embedded" => IkvmReferenceItemDebug.Embedded,
_ => IkvmReferenceItemDebug.None
};

/// <summary>
/// Attempts to resolve the references given by the reference string <paramref name="references"/> for
/// <paramref name="item"/> against <paramref name="map"/>.
Expand Down Expand Up @@ -229,7 +244,7 @@ public IkvmReferenceItem(ITaskItem item)
/// <summary>
/// Compile in debug mode.
/// </summary>
public bool Debug { get; set; }
public IkvmReferenceItemDebug Debug { get; set; }

/// <summary>
/// Path to the file to sign the assembly.
Expand Down Expand Up @@ -279,14 +294,29 @@ public void Save()
Item.SetMetadata(IkvmReferenceItemMetadata.StagePath, StagePath);
Item.SetMetadata(IkvmReferenceItemMetadata.StageSymbolsPath, StageSymbolsPath);
Item.SetMetadata(IkvmReferenceItemMetadata.Aliases, Aliases);
Item.SetMetadata(IkvmReferenceItemMetadata.Debug, Debug ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.Debug, ToString(Debug));
Item.SetMetadata(IkvmReferenceItemMetadata.KeyFile, KeyFile);
Item.SetMetadata(IkvmReferenceItemMetadata.DelaySign, DelaySign ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.Private, Private ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.ReferenceOutputAssembly, ReferenceOutputAssembly ? "true" : "false");
Item.SetMetadata(IkvmReferenceItemMetadata.ResolvedReferences, string.Join(IkvmReferenceItemMetadata.PropertySeperatorString, ResolvedReferences));
}

/// <summary>
/// Converts the enum value to a string.
/// </summary>
/// <param name="debug"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
string ToString(IkvmReferenceItemDebug debug) => debug switch
{
IkvmReferenceItemDebug.None => "none",
IkvmReferenceItemDebug.Full => "full",
IkvmReferenceItemDebug.Portable => "portable",
IkvmReferenceItemDebug.Embedded => "embedded",
_ => throw new NotImplementedException(),
};

}

}
14 changes: 14 additions & 0 deletions src/IKVM.MSBuild.Tasks/IkvmReferenceItemDebug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace IKVM.MSBuild.Tasks
{

enum IkvmReferenceItemDebug
{

None,
Full,
Portable,
Embedded,

}

}
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tasks/IkvmReferenceItemPrepare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ internal async Task<string> CalculateIkvmIdentityAsync(IkvmReferenceItem item, C
manifest.WriteLine("AssemblyVersion={0}", item.AssemblyVersion);
manifest.WriteLine("AssemblyFileVersion={0}", item.AssemblyFileVersion);
manifest.WriteLine("ClassLoader={0}", item.ClassLoader);
manifest.WriteLine("Debug={0}", item.Debug ? "true" : "false");
manifest.WriteLine("Debug={0}", Enum.GetName(typeof(IkvmReferenceItemDebug), item.Debug));
manifest.WriteLine("KeyFile={0}", string.IsNullOrWhiteSpace(item.KeyFile) == false ? await fileIdentityUtil.GetIdentityForFileAsync(item.KeyFile, Log, cancellationToken) : "");
manifest.WriteLine("DelaySign={0}", item.DelaySign ? "true" : "false");

Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tests/IKVM.MSBuild.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Buildalyzer" Version="5.0.1" />
<PackageReference Include="Buildalyzer" Version="6.0.4" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.MSBuild.Tests/Project/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.0",
"version": "7.0.100",
"rollForward": "latestFeature"
}
}
Loading