Skip to content

Commit

Permalink
IKVM 8.6.1.0 Compiler Update
Browse files Browse the repository at this point in the history
 + STRICT Floating Point
 + precompilation optimizations
 + NEW IKVMC option: -preoptimize
 + NEW IKVM/IKVMW option: -Xpreoptimize
  • Loading branch information
jessiepathfinder committed Dec 16, 2019
1 parent d4156bd commit b27b27f
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 48 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.5.2.0")]
[assembly: AssemblyVersion("8.6.1.0")]

#if SIGNCODE
#pragma warning disable 1699
Expand Down
8 changes: 7 additions & 1 deletion ikvm/starter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Jeroen Frijters
using IKVM.Internal;
using ikvm.runtime;
using java.lang.reflect;
using jessielesbian.IKVM;

public static class Starter
{
Expand Down Expand Up @@ -288,11 +289,15 @@ static int Main(string[] args)
}
else if(arg.StartsWith("-Xoptimize:")){
try{
jessielesbian.IKVM.Helper.optpasses = (int)Convert.ToUInt32(arg.Replace("-Xoptimize:", ""));
Helper.optpasses = (int)Convert.ToUInt32(arg.Replace("-Xoptimize:", ""));
} catch{
Console.Error.WriteLine("SORRY, IKVM.NET experimental optimizations disabled, reason: negative or invalid number of optimization passes.");
}
}
else if(arg == "-Xpreoptimize")
{
Helper.enableJITPreOptimization = true;
}
else
{
Console.Error.WriteLine("{0}: illegal argument", arg);
Expand Down Expand Up @@ -440,6 +445,7 @@ private static void PrintXHelp()
Console.Error.WriteLine(" -Xnoglobbing Disable argument globbing");
Console.Error.WriteLine(" -Xverify Enable strict class file verification");
Console.Error.WriteLine(" -Xoptimize:n Enable IKVM.NET experimental optimizations and use N passes of optimization");
Console.Error.WriteLine(" -Xpreoptimize Enable precompilation optimizations");
Console.Error.WriteLine();
Console.Error.WriteLine("The -X options are non-standard and subject to change without notice.");
Console.Error.WriteLine();
Expand Down
17 changes: 15 additions & 2 deletions ikvmc/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Jeroen Frijters
using IKVM.Internal;
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using jessielesbian.IKVM;
using Type = IKVM.Reflection.Type;

sealed class FatalCompilerErrorException : Exception
Expand Down Expand Up @@ -400,7 +401,14 @@ internal static byte[] ReadAllBytes(FileInfo path)
{
try
{
return File.ReadAllBytes(path.FullName);
//ULTRA fast 2-step file reader by Jessie Lesbian
FileStream fileStream = path.OpenRead();
MemoryStream memoryStream = new MemoryStream((int) fileStream.Length);
fileStream.CopyTo(memoryStream);
fileStream.Dispose();
byte[] bytes = memoryStream.ToArray();
memoryStream.Dispose();
return bytes;
}
catch (Exception x)
{
Expand Down Expand Up @@ -481,6 +489,7 @@ private static void PrintHelp()
Console.Error.WriteLine("-strictfinalfieldsemantics Don't allow final fields to be modified outside");
Console.Error.WriteLine(" of initializer methods");
Console.Error.WriteLine("-optimize:n Enable IKVM.NET experimental optimizations and use N passes of optimization");
Console.Error.WriteLine("-preoptimize Enable precompilation optimizations");
Console.Error.WriteLine();
Console.Error.WriteLine(" - ERRORS AND WARNINGS -");
Console.Error.WriteLine("-nowarn:<warning[:key]> Suppress specified warnings");
Expand Down Expand Up @@ -1012,11 +1021,15 @@ void ContinueParseCommandLine(IEnumerator<string> arglist, List<CompilerOptions>
else if(s.StartsWith("-optimize:"))
{
try{
jessielesbian.IKVM.Helper.optpasses = (int)Convert.ToUInt32(s.Replace("-optimize:", ""));
Helper.optpasses = (int)Convert.ToUInt32(s.Replace("-optimize:", ""));
} catch{
Console.Error.WriteLine("SORRY, IKVM.NET experimental optimizations disabled, reason: negative or invalid number of optimization passes.");
}
}
else if(s == "-preoptimize")
{
Helper.enableJITPreOptimization = true;
}
else
{
throw new FatalCompilerErrorException(Message.UnrecognizedOption, s);
Expand Down
2 changes: 1 addition & 1 deletion ikvmc/CompilerClassLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4169,4 +4169,4 @@ internal object[][] ToArray()
return list.ToArray();
}
}
}
}
Binary file modified openjdk/commonAttributes.class
Binary file not shown.
1 change: 1 addition & 0 deletions openjdk/openjdk.build
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<arg value="-warnaserror" />
<!-- we need optimizations since Jessie Lesbian had waiting difficulties. -->
<arg value="-optimize:5" />
<arg value="-preoptimize" />
<arg value="-removeassertions" />
<arg value="-compressresources" />
<arg value="-opt:fields" />
Expand Down
56 changes: 14 additions & 42 deletions runtime/compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Jeroen Frijters
using System.Diagnostics.SymbolStore;
using IKVM.Attributes;
using IKVM.Internal;
using jessielesbian.IKVM;

using ExceptionTableEntry = IKVM.Internal.ClassFile.Method.ExceptionTableEntry;
using LocalVariableTableEntry = IKVM.Internal.ClassFile.Method.LocalVariableTableEntry;
Expand Down Expand Up @@ -288,7 +289,6 @@ sealed class Compiler
private bool nonleaf;
private readonly bool debug;
private readonly bool keepAlive;
private readonly bool strictfp;
private readonly bool emitLineNumbers;
private int[] scopeBegin;
private int[] scopeClose;
Expand Down Expand Up @@ -336,7 +336,6 @@ private Compiler(DynamicTypeWrapper.FinishContext context, TypeWrapper host, Dyn
this.m = m;
this.ilGenerator = ilGenerator;
this.debug = classLoader.EmitDebugInfo;
this.strictfp = m.IsStrictfp;
if(mw.IsConstructor)
{
MethodWrapper finalize = clazz.GetMethodWrapper(StringConstants.FINALIZE, StringConstants.SIG_VOID, true);
Expand Down Expand Up @@ -1064,6 +1063,10 @@ private void Compile(Block block, int startIndex)
}
}
}
if(Helper.enableJITPreOptimization)
{
code = Helper.Optimize(code);
}
for(int i = 0; i < code.Length; i++)
{
Instruction instr = code[i];
Expand Down Expand Up @@ -1357,11 +1360,7 @@ private void Compile(Block block, int startIndex)
FieldWrapper field = cpi.GetField();
TypeWrapper tw = field.FieldTypeWrapper;
tw.EmitConvStackTypeToSignatureType(ilGenerator, ma.GetStackTypeWrapper(i, 0));
if(strictfp)
{
// no need to convert
}
else if(tw == PrimitiveTypeWrapper.DOUBLE)
if(tw == PrimitiveTypeWrapper.DOUBLE)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
Expand Down Expand Up @@ -1390,11 +1389,7 @@ private void Compile(Block block, int startIndex)
ilGenerator.Emit(OpCodes.Ldloc, temp);
}
tw.EmitConvStackTypeToSignatureType(ilGenerator, ma.GetStackTypeWrapper(i, 0));
if(strictfp)
{
// no need to convert
}
else if(tw == PrimitiveTypeWrapper.DOUBLE)
if(tw == PrimitiveTypeWrapper.DOUBLE)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
Expand Down Expand Up @@ -2262,10 +2257,7 @@ private void Compile(Block block, int startIndex)
break;
case NormalizedByteCode.__dadd:
ilGenerator.Emit(OpCodes.Add);
if(strictfp)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
ilGenerator.Emit(OpCodes.Conv_R8);
break;
case NormalizedByteCode.__isub:
case NormalizedByteCode.__lsub:
Expand All @@ -2277,10 +2269,7 @@ private void Compile(Block block, int startIndex)
break;
case NormalizedByteCode.__dsub:
ilGenerator.Emit(OpCodes.Sub);
if(strictfp)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
ilGenerator.Emit(OpCodes.Conv_R8);
break;
case NormalizedByteCode.__ixor:
case NormalizedByteCode.__lxor:
Expand All @@ -2304,10 +2293,7 @@ private void Compile(Block block, int startIndex)
break;
case NormalizedByteCode.__dmul:
ilGenerator.Emit(OpCodes.Mul);
if(strictfp)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
ilGenerator.Emit(OpCodes.Conv_R8);
break;
case NormalizedByteCode.__idiv:
ilGenerator.Emit_idiv();
Expand All @@ -2321,10 +2307,7 @@ private void Compile(Block block, int startIndex)
break;
case NormalizedByteCode.__ddiv:
ilGenerator.Emit(OpCodes.Div);
if(strictfp)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
ilGenerator.Emit(OpCodes.Conv_R8);
break;
case NormalizedByteCode.__irem:
case NormalizedByteCode.__lrem:
Expand Down Expand Up @@ -2361,10 +2344,7 @@ private void Compile(Block block, int startIndex)
break;
case NormalizedByteCode.__drem:
ilGenerator.Emit(OpCodes.Rem);
if(strictfp)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
ilGenerator.Emit(OpCodes.Conv_R8);
break;
case NormalizedByteCode.__ishl:
ilGenerator.Emit_And_I4(31);
Expand Down Expand Up @@ -2812,11 +2792,7 @@ private void Compile(Block block, int startIndex)
private void EmitReturnTypeConversion(TypeWrapper returnType)
{
returnType.EmitConvSignatureTypeToStackType(ilGenerator);
if (!strictfp)
{
// no need to convert
}
else if (returnType == PrimitiveTypeWrapper.DOUBLE)
if (returnType == PrimitiveTypeWrapper.DOUBLE)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
Expand Down Expand Up @@ -3562,11 +3538,7 @@ private void DynamicGetPutField(Instruction instr, int i)
if (kind == ClassFile.RefKind.putField || kind == ClassFile.RefKind.putStatic)
{
fieldType.EmitConvStackTypeToSignatureType(ilGenerator, ma.GetStackTypeWrapper(i, 0));
if (strictfp)
{
// no need to convert
}
else if (fieldType == PrimitiveTypeWrapper.DOUBLE)
if (fieldType == PrimitiveTypeWrapper.DOUBLE)
{
ilGenerator.Emit(OpCodes.Conv_R8);
}
Expand Down
Loading

0 comments on commit b27b27f

Please sign in to comment.