diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/BootJavaInterop.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/BootJavaInterop.java index 2ebd5a924..eb40436f7 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/BootJavaInterop.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/BootJavaInterop.java @@ -232,9 +232,9 @@ protected SixModelObject computeInterop(ThreadContext tc, Class klass) { CompilationUnit adaptorUnit; try { - adaptorUnit = (CompilationUnit) adaptor.constructed.newInstance(); - } catch (ReflectiveOperationException roe) { - throw new RuntimeException(roe); + adaptorUnit = (CompilationUnit) adaptor.constructed.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); } adaptorUnit.initializeCompilationUnit(tc); diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/CompilationUnit.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/CompilationUnit.java index a0cd5c27f..131bb9644 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/CompilationUnit.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/CompilationUnit.java @@ -63,9 +63,15 @@ public static void enterFromMain(Class cuType, int entryCodeRefIdx, String[] */ public static CompilationUnit setupCompilationUnit(ThreadContext tc, Class cuType, boolean shared) throws InstantiationException, IllegalAccessException { - CompilationUnit cu = (CompilationUnit)cuType.newInstance(); - cu.shared = shared; - cu.initializeCompilationUnit(tc); + CompilationUnit cu = null; + try { + cu = (CompilationUnit)cuType.getDeclaredConstructor().newInstance(); + cu.shared = shared; + cu.initializeCompilationUnit(tc); + } + catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); + } return cu; } diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/LibraryLoader.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/LibraryLoader.java index a9677fb86..18f2d39e1 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/LibraryLoader.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/LibraryLoader.java @@ -66,10 +66,15 @@ public void load(ThreadContext tc, byte[] buffer) { } private static void loadClass(ThreadContext tc, Class c) throws Throwable { - CompilationUnit cu = (CompilationUnit)c.newInstance(); - cu.shared = tc.gc.sharingHint; - cu.initializeCompilationUnit(tc); - cu.runLoadIfAvailable(tc); + try { + CompilationUnit cu = (CompilationUnit)c.getDeclaredConstructor().newInstance(); + cu.shared = tc.gc.sharingHint; + cu.initializeCompilationUnit(tc); + cu.runLoadIfAvailable(tc); + } + catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); + } } private static Class loadJar(byte[] buffer) throws Exception { diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/NativeCallOps.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/NativeCallOps.java index 392880e2e..3c07d16c8 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/NativeCallOps.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/NativeCallOps.java @@ -115,7 +115,7 @@ public static SixModelObject call(SixModelObject returns, SixModelObject callObj CPPStructREPRData repr_data = (CPPStructREPRData)returns.st.REPRData; Class structClass = repr_data.structureClass; cppstruct = (CPPStructInstance)returns.st.REPR.allocate(tc, returns.st); - cppstruct.storage = (Structure)structClass.newInstance(); + cppstruct.storage = (Structure)structClass.getDeclaredConstructor().newInstance(); cArgs[i] = cppstruct.storage; } else { @@ -188,7 +188,9 @@ public static SixModelObject call(SixModelObject returns, SixModelObject callObj return toNQPType(tc, call.ret_type, returns, returned); } } - catch (ControlException e) { throw e; } + catch (ControlException e) { + throw ExceptionHandling.dieInternal(tc, e); + } catch (Throwable t) { throw ExceptionHandling.dieInternal(tc, t); } diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java index 912496d5b..d6e9b7619 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java @@ -56,6 +56,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -3804,8 +3805,10 @@ public static SixModelObject iter(SixModelObject agg, ThreadContext tc) { else if (agg.st.REPR instanceof VMHash) { SixModelObject iterType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.hashIteratorType; VMIterInstance iter = (VMIterInstance)iterType.st.REPR.allocate(tc, iterType.st); + VMHashInstance hash = (VMHashInstance)agg; + Map storage = new HashMap< >(hash.storage); iter.target = agg; - iter.hashKeyIter = ((HashMap)((VMHashInstance)agg).storage.clone()).keySet().iterator(); + iter.hashKeyIter = storage.keySet().iterator(); iter.iterMode = VMIterInstance.MODE_HASH; return iter; } @@ -7023,12 +7026,12 @@ public static long coerce_n2i(double in) { return Long.MIN_VALUE; } else { - return new Double(in).longValue(); + return Double.valueOf(in).longValue(); } } public static double coerce_i2n(long in) { - return new Long(in).doubleValue(); + return Long.valueOf(in).doubleValue(); } /* Long literal workaround. */ @@ -7387,7 +7390,7 @@ public static SixModelObject loadcompunit(SixModelObject obj, long compileeHLL, try { EvalResult res = (EvalResult)obj; Class cuClass = tc.gc.byteClassLoader.defineClass(res.jc.name, res.jc.bytes); - res.cu = (CompilationUnit) cuClass.newInstance(); + res.cu = (CompilationUnit) cuClass.getDeclaredConstructor().newInstance(); if (compileeHLL != 0) usecompileehllconfig(tc); res.cu.initializeCompilationUnit(tc); @@ -7396,11 +7399,8 @@ public static SixModelObject loadcompunit(SixModelObject obj, long compileeHLL, res.jc = null; return obj; } - catch (ControlException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionHandling.dieInternal(tc, e); } } public static long iscompunit(SixModelObject obj, ThreadContext tc) { diff --git a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CPPStruct.java b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CPPStruct.java index 3f8b3a093..9874b9507 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CPPStruct.java +++ b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CPPStruct.java @@ -85,11 +85,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) { CPPStructREPRData repr_data = (CPPStructREPRData) st.REPRData; obj.st = st; try { - obj.storage = (Structure) repr_data.structureClass.newInstance(); + obj.storage = (Structure) repr_data.structureClass.getDeclaredConstructor().newInstance(); } - catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - throw new RuntimeException(e); + catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); } return obj; } diff --git a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CStruct.java b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CStruct.java index 0c647ca8e..7ccd47c2b 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CStruct.java +++ b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CStruct.java @@ -85,11 +85,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) { CStructREPRData repr_data = (CStructREPRData) st.REPRData; obj.st = st; try { - obj.storage = (Structure) repr_data.structureClass.newInstance(); + obj.storage = (Structure) repr_data.structureClass.getDeclaredConstructor().newInstance(); } - catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - throw new RuntimeException(e); + catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); } return obj; } diff --git a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CUnion.java b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CUnion.java index 1f3d1c296..bfb128b76 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CUnion.java +++ b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CUnion.java @@ -82,11 +82,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) { CUnionREPRData repr_data = (CUnionREPRData) st.REPRData; obj.st = st; try { - obj.storage = (Union) repr_data.structureClass.newInstance(); + obj.storage = (Union) repr_data.structureClass.getDeclaredConstructor().newInstance(); } - catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - throw new RuntimeException(e); + catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); } return obj; } diff --git a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6Opaque.java b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6Opaque.java index ea14f357e..2ce94959f 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6Opaque.java +++ b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6Opaque.java @@ -258,12 +258,15 @@ private void installJVMType(ThreadContext tc, STable st, List attrInfo ((P6OpaqueREPRData)st.REPRData).jvmClass = use; try { - ((P6OpaqueREPRData)st.REPRData).instance = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.newInstance(); + ((P6OpaqueREPRData)st.REPRData).instance = + (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.getDeclaredConstructor().newInstance(); } - catch (InstantiationException | IllegalAccessException e) { - throw new RuntimeException(e); + catch (ReflectiveOperationException e) { + throw ExceptionHandling.dieInternal(tc, e); + } + finally { + ((P6OpaqueREPRData)st.REPRData).instance.st = st; } - ((P6OpaqueREPRData)st.REPRData).instance.st = st; } private Class generateJVMClass(ThreadContext tc, List attrInfoList) { diff --git a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6OpaqueBaseInstance.java b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6OpaqueBaseInstance.java index ffc5581c0..d540d4b22 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6OpaqueBaseInstance.java +++ b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6OpaqueBaseInstance.java @@ -130,9 +130,7 @@ public SixModelObject cas_attribute_boxed(ThreadContext tc, SixModelObject class catch (Exception e) { throw ExceptionHandling.dieInternal(tc, e); } - finally { - return result == null ? Ops.createNull(tc) : result; - } + return result == null ? Ops.createNull(tc) : result; } @Override @@ -161,9 +159,7 @@ public SixModelObject atomic_load_attribute_boxed(ThreadContext tc, SixModelObje catch (Exception e) { throw ExceptionHandling.dieInternal(tc, e); } - finally { - return result == null ? Ops.createNull(tc) : result; - } + return result == null ? Ops.createNull(tc) : result; } public SixModelObject posDelegate() { diff --git a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/VMIterInstance.java b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/VMIterInstance.java index 088f1546a..e5601f8c5 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/VMIterInstance.java +++ b/src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/VMIterInstance.java @@ -106,7 +106,7 @@ public boolean boolify() { public String key_s(ThreadContext tc) { switch (iterMode) { case MODE_ARRAY: - return new Long(idx).toString(); + return Long.valueOf(idx).toString(); case MODE_HASH: if (beforeStart || afterEnd) throw ExceptionHandling.dieInternal(tc, "You have not advanced to the first item of the hash iterator, or have gone past the end");