Skip to content

Commit

Permalink
IKVM.NET 8.6.4.0 Compiler revamp
Browse files Browse the repository at this point in the history
 + optimized preoptimizer
 + removed flow optimizations
 + changed the behavior of arrays in Dynamic Mode
  • Loading branch information
jessiepathfinder committed Dec 30, 2019
1 parent 94f3fff commit 5df8be7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CommonAssemblyInfo.cs.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using System.Reflection;
[assembly: AssemblyCopyright("Copyright (C) 2019 Jessie Lesbian (based on work by Jeroen Frijters and Windward Studios)")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("8.6.3.0")]
[assembly: AssemblyVersion("8.6.4.0")]

#if SIGNCODE
#pragma warning disable 1699
Expand Down
Binary file modified openjdk/commonAttributes.class
Binary file not shown.
Binary file modified openjdk/java/lang/PropertyConstants.class
Binary file not shown.
5 changes: 3 additions & 2 deletions runtime/ByteCodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Jeroen Frijters
using System.Threading;
using IKVM.Attributes;
using IKVM.Internal;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace IKVM.Runtime
Expand Down Expand Up @@ -189,7 +190,7 @@ public static void DynamicAastore(object arrayref, int index, object val)
{
#if !FIRST_PASS
Profiler.Count("DynamicAastore");
((Array)arrayref).SetValue(val, index);
((IList<object>)arrayref)[index] = val;
#endif
}

Expand All @@ -200,7 +201,7 @@ public static object DynamicAaload(object arrayref, int index)
return null;
#else
Profiler.Count("DynamicAaload");
return ((Array)arrayref).GetValue(index);
return ((IList<object>)arrayref)[index];
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions runtime/compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2069,8 +2069,12 @@ private void Compile(Block block, int startIndex)
TypeWrapper tw = ma.GetRawStackTypeWrapper(i, 1);
if(tw.IsUnloadable)
{
#if STATIC_COMPILER
Profiler.Count("EmitDynamicAaload");
ilGenerator.Emit(OpCodes.Call, ByteCodeHelperMethods.DynamicAaload);
#else
ilGenerator.Emit(OpCodes.Callvirt, Helper.ArrayLoad);
#endif
}
else
{
Expand Down Expand Up @@ -2141,8 +2145,12 @@ private void Compile(Block block, int startIndex)
TypeWrapper tw = ma.GetRawStackTypeWrapper(i, 2);
if(tw.IsUnloadable)
{
#if STATIC_COMPILER
Profiler.Count("EmitDynamicAastore");
ilGenerator.Emit(OpCodes.Call, ByteCodeHelperMethods.DynamicAastore);
#else
ilGenerator.Emit(OpCodes.Callvirt, Helper.ArrayLoad);
#endif
}
else
{
Expand Down
71 changes: 17 additions & 54 deletions runtime/jessielesbian.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
using System;
using System.Collections.Generic;
using IKVM.Internal;
using System.Reflection;
using Instruction = IKVM.Internal.ClassFile.Method.Instruction;
using System.Collections.Generic;

//Do you believe in high-quality code by Female/LGBT programmers? Leave u/jessielesbian a PM on Reddit!

namespace jessielesbian.IKVM
{
public static class Helper
{
static Helper()
{
Array array = new object[0];
ArrayLoad = new Func<int, object>(array.GetValue).Method;
ArrayStore = new Action<object, int>(array.SetValue).Method;
}
public static int optpasses = 0;
public static bool enableJITPreOptimization = false;
internal static bool experimentalOptimizations
{
get
{

return (optpasses > 0);
}
}
Expand Down Expand Up @@ -122,14 +129,6 @@ internal static Instruction[] Optimize(Instruction[] instructions)

instructions = (Instruction[])instructions.Clone();
int optimizations = 1279738452;
List<int> brtargets = new List<int>(instructions.Length);
for (int i = 1; i < instructions.Length; i++)
{
if (IsBranchInstruction(instructions[i]))
{
brtargets.Add(i);
}
}
while (optimizations != 0)
{
optimizations = 0;
Expand All @@ -140,21 +139,9 @@ internal static Instruction[] Optimize(Instruction[] instructions)
{
prevIndex--;
}
if (brtargets.Contains(prevIndex) || IsBranchInstruction(instructions[prevIndex]))
{
continue;
}
Instruction current = instructions[i];
Instruction prev = instructions[i - 1];
if (brtargets.Contains(i))
{
continue;
}
if (brtargets.Contains(i - 1))
{
continue;
}
if (brtargets.Contains(i + 1))
if (IsBranchInstruction(current) || IsBranchInstruction(prev))
{
continue;
}
Expand Down Expand Up @@ -311,7 +298,7 @@ internal static Instruction[] Optimize(Instruction[] instructions)
optimizations = optimizations + 1;
}
}
//peephole optimization: remove unnecessary swaps
//peephole optimization: remove unnecessary swaps + branch optimizations
if (prev.NormalizedOpCode == NormalizedByteCode.__swap)
{
switch (current.NormalizedOpCode)
Expand Down Expand Up @@ -353,41 +340,17 @@ internal static Instruction[] Optimize(Instruction[] instructions)
break;
}
}
//branch optimizations
if(prev.NormalizedOpCode == NormalizedByteCode.__aconst_null)
{
if(current.NormalizedOpCode == NormalizedByteCode.__ifnull)
{
prev = GetInstuction(NormalizedByteCode.__nop);
current.PatchOpCode(NormalizedByteCode.__goto);
optimizations = optimizations + 1;
}
else if (current.NormalizedOpCode == NormalizedByteCode.__ifnonnull)
{
prev = GetInstuction(NormalizedByteCode.__nop);
current = prev;
optimizations = optimizations + 1;
}
}
if(IsBranchInstruction(current))
{
Instruction target = instructions[current.TargetIndex];
if (target.NormalizedOpCode == NormalizedByteCode.__goto)
{
current.TargetIndex = target.TargetIndex;
optimizations = optimizations + 1;
}
else if(target.NormalizedOpCode == NormalizedByteCode.__nop)
{
current.TargetIndex++;
optimizations = optimizations + 1;
}
}
instructions[i] = current;
instructions[i - 1] = prev;
}
}
return instructions;
}
internal static readonly MethodInfo ArrayLoad;
internal static readonly MethodInfo ArrayStore;
public static object aaload(Array array, int index)
{
return array.GetValue(index);
}
}
}
1 change: 1 addition & 0 deletions runtime/vm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Jeroen Frijters
using System.Security;
using System.Security.Permissions;
using IKVM.Internal;
using System.Collections.Generic;

#if !STATIC_COMPILER && !STUB_GENERATOR
namespace IKVM.Internal
Expand Down

0 comments on commit 5df8be7

Please sign in to comment.