You've already forked linux-packaging-mono
Imported Upstream version 3.10.0
Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
1371
external/ikvm/runtime/openjdk/java.io.cs
vendored
Normal file
1371
external/ikvm/runtime/openjdk/java.io.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
179
external/ikvm/runtime/openjdk/java.lang.cs
vendored
179
external/ikvm/runtime/openjdk/java.lang.cs
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2007-2013 Jeroen Frijters
|
||||
Copyright (C) 2007-2014 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -96,6 +96,57 @@ static class Java_java_lang_Class
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] getRawTypeAnnotations(java.lang.Class thisClass)
|
||||
{
|
||||
return TypeWrapper.FromClass(thisClass).GetRawTypeAnnotations();
|
||||
}
|
||||
|
||||
#if !FIRST_PASS
|
||||
private sealed class ConstantPoolImpl : sun.reflect.ConstantPool
|
||||
{
|
||||
private readonly object[] constantPool;
|
||||
|
||||
internal ConstantPoolImpl(object[] constantPool)
|
||||
{
|
||||
this.constantPool = constantPool;
|
||||
}
|
||||
|
||||
public override string getUTF8At(int index)
|
||||
{
|
||||
return (string)constantPool[index];
|
||||
}
|
||||
|
||||
public override int getIntAt(int index)
|
||||
{
|
||||
return (int)constantPool[index];
|
||||
}
|
||||
|
||||
public override long getLongAt(int index)
|
||||
{
|
||||
return (long)constantPool[index];
|
||||
}
|
||||
|
||||
public override float getFloatAt(int index)
|
||||
{
|
||||
return (float)constantPool[index];
|
||||
}
|
||||
|
||||
public override double getDoubleAt(int index)
|
||||
{
|
||||
return (double)constantPool[index];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static object getConstantPool(java.lang.Class thisClass)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return null;
|
||||
#else
|
||||
return new ConstantPoolImpl(TypeWrapper.FromClass(thisClass).GetConstantPool());
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool isInstance(java.lang.Class thisClass, object obj)
|
||||
{
|
||||
return TypeWrapper.FromClass(thisClass).IsInstance(obj);
|
||||
@ -169,6 +220,14 @@ static class Java_java_lang_Class
|
||||
return "void";
|
||||
}
|
||||
}
|
||||
if (tw.IsUnsafeAnonymous)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
// for OpenJDK compatibility and debugging convenience we modify the class name to
|
||||
// include the identity hashcode of the class object
|
||||
return tw.Name + "/" + java.lang.System.identityHashCode(thisClass);
|
||||
#endif
|
||||
}
|
||||
return tw.Name;
|
||||
}
|
||||
|
||||
@ -188,7 +247,7 @@ static class Java_java_lang_Class
|
||||
return super != null ? super.ClassObject : null;
|
||||
}
|
||||
|
||||
public static java.lang.Class[] getInterfaces(java.lang.Class thisClass)
|
||||
public static java.lang.Class[] getInterfaces0(java.lang.Class thisClass)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return null;
|
||||
@ -252,7 +311,7 @@ static class Java_java_lang_Class
|
||||
}
|
||||
}
|
||||
|
||||
public static java.lang.Class getDeclaringClass(java.lang.Class thisClass)
|
||||
public static java.lang.Class getDeclaringClass0(java.lang.Class thisClass)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -286,9 +345,9 @@ static class Java_java_lang_Class
|
||||
return null;
|
||||
#else
|
||||
TypeWrapper wrapper = TypeWrapper.FromClass(thisClass);
|
||||
while (wrapper.IsArray)
|
||||
if (wrapper.IsArray)
|
||||
{
|
||||
wrapper = wrapper.ElementTypeWrapper;
|
||||
return null;
|
||||
}
|
||||
java.security.ProtectionDomain pd = wrapper.ClassObject.pd;
|
||||
if (pd == null)
|
||||
@ -300,18 +359,17 @@ static class Java_java_lang_Class
|
||||
{
|
||||
pd = acl.GetProtectionDomain();
|
||||
}
|
||||
else if (wrapper is AnonymousTypeWrapper)
|
||||
{
|
||||
// dynamically compiled intrinsified lamdba anonymous types end up here and should get their
|
||||
// protection domain from the host class
|
||||
pd = ClassLoaderWrapper.GetWrapperFromType(wrapper.TypeAsTBD.DeclaringType).ClassObject.pd;
|
||||
}
|
||||
}
|
||||
return pd;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void setProtectionDomain0(java.lang.Class thisClass, java.security.ProtectionDomain pd)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
thisClass.pd = pd;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static java.lang.Class getPrimitiveClass(string name)
|
||||
{
|
||||
// note that this method isn't used anymore (because it is an intrinsic (during core class library compilation))
|
||||
@ -341,7 +399,7 @@ static class Java_java_lang_Class
|
||||
}
|
||||
}
|
||||
|
||||
public static string getGenericSignature(java.lang.Class thisClass)
|
||||
public static string getGenericSignature0(java.lang.Class thisClass)
|
||||
{
|
||||
TypeWrapper tw = TypeWrapper.FromClass(thisClass);
|
||||
tw.Finish();
|
||||
@ -620,16 +678,7 @@ static class Java_java_lang_ClassLoader
|
||||
try
|
||||
{
|
||||
ClassLoaderWrapper classLoaderWrapper = ClassLoaderWrapper.GetClassLoaderWrapper(thisClassLoader);
|
||||
ClassFileParseOptions cfp = ClassFileParseOptions.LineNumberTable;
|
||||
if (classLoaderWrapper.EmitDebugInfo)
|
||||
{
|
||||
cfp |= ClassFileParseOptions.LocalVariableTable;
|
||||
}
|
||||
if (classLoaderWrapper.RelaxedClassNameValidation)
|
||||
{
|
||||
cfp |= ClassFileParseOptions.RelaxedClassNameValidation;
|
||||
}
|
||||
ClassFile classFile = new ClassFile(b, off, len, name, cfp);
|
||||
ClassFile classFile = new ClassFile(b, off, len, name, classLoaderWrapper.ClassFileParseOptions, null);
|
||||
if (name != null && classFile.Name != name)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
@ -703,13 +752,13 @@ static class Java_java_lang_ClassLoader
|
||||
|
||||
static class Java_java_lang_ClassLoader_00024NativeLibrary
|
||||
{
|
||||
public static void load(object thisNativeLibrary, string name)
|
||||
public static void load(object thisNativeLibrary, string name, bool isBuiltin)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
if (VirtualFileSystem.IsVirtualFS(name))
|
||||
{
|
||||
// we fake success for native libraries loaded from VFS
|
||||
((java.lang.ClassLoader.NativeLibrary)thisNativeLibrary).handle = -1;
|
||||
((java.lang.ClassLoader.NativeLibrary)thisNativeLibrary).loaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -725,7 +774,8 @@ static class Java_java_lang_ClassLoader_00024NativeLibrary
|
||||
private static void doLoad(object thisNativeLibrary, string name)
|
||||
{
|
||||
java.lang.ClassLoader.NativeLibrary lib = (java.lang.ClassLoader.NativeLibrary)thisNativeLibrary;
|
||||
lib.handle = IKVM.Runtime.JniHelper.LoadLibrary(name, TypeWrapper.FromClass(lib.fromClass).GetClassLoader());
|
||||
lib.handle = IKVM.Runtime.JniHelper.LoadLibrary(name, TypeWrapper.FromClass(java.lang.ClassLoader.NativeLibrary.getFromClass()).GetClassLoader());
|
||||
lib.loaded = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -736,17 +786,22 @@ static class Java_java_lang_ClassLoader_00024NativeLibrary
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public static void unload(object thisNativeLibrary)
|
||||
public static void unload(object thisNativeLibrary, string name, bool isBuiltin)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
java.lang.ClassLoader.NativeLibrary lib = (java.lang.ClassLoader.NativeLibrary)thisNativeLibrary;
|
||||
long handle = Interlocked.Exchange(ref lib.handle, 0);
|
||||
if (handle != 0)
|
||||
{
|
||||
IKVM.Runtime.JniHelper.UnloadLibrary(handle, TypeWrapper.FromClass(lib.fromClass).GetClassLoader());
|
||||
IKVM.Runtime.JniHelper.UnloadLibrary(handle, TypeWrapper.FromClass(java.lang.ClassLoader.NativeLibrary.getFromClass()).GetClassLoader());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static string findBuiltinLib(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_java_lang_Compiler
|
||||
@ -823,9 +878,12 @@ static class Java_java_lang_Package
|
||||
{
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
string path = VirtualFileSystem.GetAssemblyResourcesPath(JVM.CoreAssembly) + "resources.jar";
|
||||
foreach (string pkg in ClassLoaderWrapper.GetBootstrapClassLoader().GetPackages())
|
||||
foreach (KeyValuePair<string, string[]> pkgs in ClassLoaderWrapper.GetBootstrapClassLoader().GetPackageInfo())
|
||||
{
|
||||
dict[pkg.Replace('.', '/') + "/"] = path;
|
||||
foreach (string pkg in pkgs.Value)
|
||||
{
|
||||
dict[pkg.Replace('.', '/') + "/"] = path;
|
||||
}
|
||||
}
|
||||
Interlocked.CompareExchange(ref systemPackages, dict, null);
|
||||
}
|
||||
@ -927,18 +985,11 @@ static class Java_java_lang_SecurityManager
|
||||
{
|
||||
StackFrame frame = trace.GetFrame(i);
|
||||
MethodBase method = frame.GetMethod();
|
||||
Type type = method.DeclaringType;
|
||||
// NOTE these checks should be the same as the ones in Reflection.getCallerClass
|
||||
if (Java_sun_reflect_Reflection.IsHideFromJava(method)
|
||||
|| type == null
|
||||
|| type.Assembly == typeof(object).Assembly
|
||||
|| type.Assembly == typeof(Java_java_lang_SecurityManager).Assembly
|
||||
|| type.Assembly == jniAssembly
|
||||
|| type == typeof(java.lang.reflect.Constructor)
|
||||
|| type == typeof(java.lang.reflect.Method))
|
||||
if (Java_sun_reflect_Reflection.IsHideFromStackWalk(method))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Type type = method.DeclaringType;
|
||||
if (type == typeof(java.lang.SecurityManager))
|
||||
{
|
||||
continue;
|
||||
@ -1068,20 +1119,6 @@ static class Java_java_lang_StrictMath
|
||||
#endif
|
||||
}
|
||||
|
||||
public static double ceil(double d)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return 0;
|
||||
#else
|
||||
return ikvm.@internal.JMath.ceil(d);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static double floor(double d)
|
||||
{
|
||||
return fdlibm.floor(d);
|
||||
}
|
||||
|
||||
public static double atan2(double y, double x)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
@ -1111,15 +1148,6 @@ static class Java_java_lang_StrictMath
|
||||
return Math.Tanh(d);
|
||||
}
|
||||
|
||||
public static double rint(double d)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return 0;
|
||||
#else
|
||||
return ikvm.@internal.JMath.rint(d);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static double hypot(double a, double b)
|
||||
{
|
||||
return fdlibm.__ieee754_hypot(a, b);
|
||||
@ -1223,9 +1251,14 @@ static class Java_java_lang_ProcessImpl
|
||||
{
|
||||
public static string mapVfsExecutable(string path)
|
||||
{
|
||||
if (VirtualFileSystem.IsVirtualFS(path))
|
||||
string unquoted = path;
|
||||
if (unquoted.Length > 2 && unquoted[0] == '"' && unquoted[unquoted.Length - 1] == '"')
|
||||
{
|
||||
return VirtualFileSystem.MapExecutable(path);
|
||||
unquoted = unquoted.Substring(1, unquoted.Length - 2);
|
||||
}
|
||||
if (VirtualFileSystem.IsVirtualFS(unquoted))
|
||||
{
|
||||
return VirtualFileSystem.MapExecutable(unquoted);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
@ -1250,7 +1283,7 @@ static class Java_java_lang_ProcessImpl
|
||||
for (; ; )
|
||||
{
|
||||
string str = cmdstr.Substring(0, pos);
|
||||
if (Path.IsPathRooted(str))
|
||||
if (IsPathRooted(str))
|
||||
{
|
||||
if (Exists(str))
|
||||
{
|
||||
@ -1303,6 +1336,18 @@ static class Java_java_lang_ProcessImpl
|
||||
return list;
|
||||
}
|
||||
|
||||
private static bool IsPathRooted(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Path.IsPathRooted(path);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool Exists(string file)
|
||||
{
|
||||
try
|
||||
@ -1319,6 +1364,10 @@ static class Java_java_lang_ProcessImpl
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (mapVfsExecutable(file) != file)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
|
@ -689,6 +689,8 @@ static class Java_java_lang_reflect_Proxy
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// we need to explicitly register the type, because the type isn't visible by normal means
|
||||
tw.GetClassLoader().SetWrapperForType(type, tw);
|
||||
TypeWrapper[] wrappers2 = tw.Interfaces;
|
||||
if (wrappers.Length != wrappers.Length)
|
||||
{
|
||||
@ -705,29 +707,50 @@ static class Java_java_lang_reflect_Proxy
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_java_lang_reflect_Field
|
||||
static class Java_java_lang_reflect_Executable
|
||||
{
|
||||
public static object getDeclaredAnnotationsImpl(java.lang.reflect.Field thisField)
|
||||
{
|
||||
FieldWrapper fw = FieldWrapper.FromField(thisField);
|
||||
return Java_java_lang_Class.AnnotationsToMap(fw.DeclaringType.GetClassLoader(), fw.DeclaringType.GetFieldAnnotations(fw));
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_java_lang_reflect_Method
|
||||
{
|
||||
public static object getDeclaredAnnotationsImpl(object methodOrConstructor)
|
||||
{
|
||||
MethodWrapper mw = MethodWrapper.FromMethodOrConstructor(methodOrConstructor);
|
||||
return Java_java_lang_Class.AnnotationsToMap(mw.DeclaringType.GetClassLoader(), mw.DeclaringType.GetMethodAnnotations(mw));
|
||||
}
|
||||
|
||||
public static object[][] getParameterAnnotationsImpl(object methodOrConstructor)
|
||||
public static object[] getParameters0(java.lang.reflect.Executable _this)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return null;
|
||||
#else
|
||||
MethodWrapper mw = MethodWrapper.FromMethodOrConstructor(methodOrConstructor);
|
||||
MethodWrapper mw = MethodWrapper.FromExecutable(_this);
|
||||
MethodParametersEntry[] methodParameters = mw.DeclaringType.GetMethodParameters(mw);
|
||||
if (methodParameters == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (methodParameters == MethodParametersEntry.Malformed)
|
||||
{
|
||||
throw new java.lang.reflect.MalformedParametersException("Invalid constant pool index");
|
||||
}
|
||||
java.lang.reflect.Parameter[] parameters = new java.lang.reflect.Parameter[methodParameters.Length];
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
parameters[i] = new java.lang.reflect.Parameter(methodParameters[i].name ?? "", methodParameters[i].flags, _this, i);
|
||||
}
|
||||
return parameters;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] getTypeAnnotationBytes0(java.lang.reflect.Executable _this)
|
||||
{
|
||||
MethodWrapper mw = MethodWrapper.FromExecutable(_this);
|
||||
return mw.DeclaringType.GetMethodRawTypeAnnotations(mw);
|
||||
}
|
||||
|
||||
public static object declaredAnnotationsImpl(java.lang.reflect.Executable executable)
|
||||
{
|
||||
MethodWrapper mw = MethodWrapper.FromExecutable(executable);
|
||||
return Java_java_lang_Class.AnnotationsToMap(mw.DeclaringType.GetClassLoader(), mw.DeclaringType.GetMethodAnnotations(mw));
|
||||
}
|
||||
|
||||
public static object[][] sharedGetParameterAnnotationsImpl(java.lang.reflect.Executable executable)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return null;
|
||||
#else
|
||||
MethodWrapper mw = MethodWrapper.FromExecutable(executable);
|
||||
object[][] objAnn = mw.DeclaringType.GetParameterAnnotations(mw);
|
||||
if (objAnn == null)
|
||||
{
|
||||
@ -758,10 +781,28 @@ static class Java_java_lang_reflect_Method
|
||||
return ann;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_java_lang_reflect_Field
|
||||
{
|
||||
public static object getDeclaredAnnotationsImpl(java.lang.reflect.Field thisField)
|
||||
{
|
||||
FieldWrapper fw = FieldWrapper.FromField(thisField);
|
||||
return Java_java_lang_Class.AnnotationsToMap(fw.DeclaringType.GetClassLoader(), fw.DeclaringType.GetFieldAnnotations(fw));
|
||||
}
|
||||
|
||||
public static byte[] getTypeAnnotationBytes0(java.lang.reflect.Field thisField)
|
||||
{
|
||||
FieldWrapper fw = FieldWrapper.FromField(thisField);
|
||||
return fw.DeclaringType.GetFieldRawTypeAnnotations(fw);
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_java_lang_reflect_Method
|
||||
{
|
||||
public static object getDefaultValue(java.lang.reflect.Method thisMethod)
|
||||
{
|
||||
MethodWrapper mw = MethodWrapper.FromMethod(thisMethod);
|
||||
MethodWrapper mw = MethodWrapper.FromExecutable(thisMethod);
|
||||
return mw.DeclaringType.GetAnnotationDefault(mw);
|
||||
}
|
||||
}
|
||||
|
702
external/ikvm/runtime/openjdk/java.net.cs
vendored
Normal file
702
external/ikvm/runtime/openjdk/java.net.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
277
external/ikvm/runtime/openjdk/java.nio.cs
vendored
Normal file
277
external/ikvm/runtime/openjdk/java.nio.cs
vendored
Normal file
@ -0,0 +1,277 @@
|
||||
/*
|
||||
Copyright (C) 2007-2013 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jeroen Frijters
|
||||
jeroen@frijters.net
|
||||
|
||||
*/
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using IKVM.Internal;
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
|
||||
[SecurityCritical]
|
||||
static class Java_java_nio_Bits
|
||||
{
|
||||
public static void copyFromShortArray(object src, long srcPos, long dstAddr, long length)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
short[] shortArray = src as short[];
|
||||
if (shortArray != null)
|
||||
{
|
||||
int index = ((int)srcPos) >> 1;
|
||||
while (length > 0)
|
||||
{
|
||||
short v = java.lang.Short.reverseBytes(shortArray[index++]);
|
||||
Marshal.WriteInt16((IntPtr)dstAddr, v);
|
||||
dstAddr += 2;
|
||||
length -= 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char[] charArray = (char[])src;
|
||||
int index = ((int)srcPos) >> 1;
|
||||
while (length > 0)
|
||||
{
|
||||
short v = java.lang.Short.reverseBytes((short)charArray[index++]);
|
||||
Marshal.WriteInt16((IntPtr)dstAddr, v);
|
||||
dstAddr += 2;
|
||||
length -= 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void copyToShortArray(long srcAddr, object dst, long dstPos, long length)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
short[] shortArray = dst as short[];
|
||||
if (shortArray != null)
|
||||
{
|
||||
int index = ((int)dstPos) >> 1;
|
||||
while (length > 0)
|
||||
{
|
||||
short v = Marshal.ReadInt16((IntPtr)srcAddr);
|
||||
shortArray[index++] = java.lang.Short.reverseBytes(v);
|
||||
srcAddr += 2;
|
||||
length -= 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char[] charArray = (char[])dst;
|
||||
int index = ((int)dstPos) >> 1;
|
||||
while (length > 0)
|
||||
{
|
||||
short v = Marshal.ReadInt16((IntPtr)srcAddr);
|
||||
charArray[index++] = (char)java.lang.Short.reverseBytes(v);
|
||||
srcAddr += 2;
|
||||
length -= 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void copyFromIntArray(object src, long srcPos, long dstAddr, long length)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
int[] intArray = src as int[];
|
||||
if (intArray != null)
|
||||
{
|
||||
int index = ((int)srcPos) >> 2;
|
||||
while (length > 0)
|
||||
{
|
||||
int v = java.lang.Integer.reverseBytes(intArray[index++]);
|
||||
Marshal.WriteInt32((IntPtr)dstAddr, v);
|
||||
dstAddr += 4;
|
||||
length -= 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] floatArray = (float[])src;
|
||||
int index = ((int)srcPos) >> 2;
|
||||
while (length > 0)
|
||||
{
|
||||
int v = java.lang.Integer.reverseBytes(java.lang.Float.floatToRawIntBits(floatArray[index++]));
|
||||
Marshal.WriteInt32((IntPtr)dstAddr, v);
|
||||
dstAddr += 4;
|
||||
length -= 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void copyToIntArray(long srcAddr, object dst, long dstPos, long length)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
int[] intArray = dst as int[];
|
||||
if (intArray != null)
|
||||
{
|
||||
int index = ((int)dstPos) >> 2;
|
||||
while (length > 0)
|
||||
{
|
||||
int v = Marshal.ReadInt32((IntPtr)srcAddr);
|
||||
intArray[index++] = java.lang.Integer.reverseBytes(v);
|
||||
srcAddr += 4;
|
||||
length -= 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] floatArray = (float[])dst;
|
||||
int index = ((int)dstPos) >> 2;
|
||||
while (length > 0)
|
||||
{
|
||||
int v = Marshal.ReadInt32((IntPtr)srcAddr);
|
||||
floatArray[index++] = java.lang.Float.intBitsToFloat(java.lang.Integer.reverseBytes(v));
|
||||
srcAddr += 4;
|
||||
length -= 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void copyFromLongArray(object src, long srcPos, long dstAddr, long length)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
long[] longArray = src as long[];
|
||||
if (longArray != null)
|
||||
{
|
||||
int index = ((int)srcPos) >> 3;
|
||||
while (length > 0)
|
||||
{
|
||||
long v = java.lang.Long.reverseBytes(longArray[index++]);
|
||||
Marshal.WriteInt64((IntPtr)dstAddr, v);
|
||||
dstAddr += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double[] doubleArray = (double[])src;
|
||||
int index = ((int)srcPos) >> 3;
|
||||
while (length > 0)
|
||||
{
|
||||
long v = java.lang.Long.reverseBytes(BitConverter.DoubleToInt64Bits(doubleArray[index++]));
|
||||
Marshal.WriteInt64((IntPtr)dstAddr, v);
|
||||
dstAddr += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void copyToLongArray(long srcAddr, object dst, long dstPos, long length)
|
||||
{
|
||||
#if !FIRST_PASS
|
||||
long[] longArray = dst as long[];
|
||||
if (longArray != null)
|
||||
{
|
||||
int index = ((int)dstPos) >> 3;
|
||||
while (length > 0)
|
||||
{
|
||||
long v = Marshal.ReadInt64((IntPtr)srcAddr);
|
||||
longArray[index++] = java.lang.Long.reverseBytes(v);
|
||||
srcAddr += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double[] doubleArray = (double[])dst;
|
||||
int index = ((int)dstPos) >> 3;
|
||||
while (length > 0)
|
||||
{
|
||||
long v = Marshal.ReadInt64((IntPtr)srcAddr);
|
||||
doubleArray[index++] = BitConverter.Int64BitsToDouble(java.lang.Long.reverseBytes(v));
|
||||
srcAddr += 8;
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_java_nio_MappedByteBuffer
|
||||
{
|
||||
private static volatile int bogusField;
|
||||
|
||||
public static bool isLoaded0(object thisMappedByteBuffer, long address, long length, int pageCount)
|
||||
{
|
||||
// on Windows, JDK simply returns false, so we can get away with that too.
|
||||
return false;
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public static void load0(object thisMappedByteBuffer, long address, long length)
|
||||
{
|
||||
int bogus = bogusField;
|
||||
while (length > 0)
|
||||
{
|
||||
// touch a byte in every page
|
||||
bogus += Marshal.ReadByte((IntPtr)address);
|
||||
length -= 4096;
|
||||
address += 4096;
|
||||
}
|
||||
// do a volatile store of the sum of the bytes to make sure the reads don't get optimized out
|
||||
bogusField = bogus;
|
||||
GC.KeepAlive(thisMappedByteBuffer);
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public static void force0(object thisMappedByteBuffer, object fd, long address, long length)
|
||||
{
|
||||
if (JVM.IsUnix)
|
||||
{
|
||||
ikvm_msync((IntPtr)address, (int)length);
|
||||
GC.KeepAlive(thisMappedByteBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// according to the JDK sources, FlushViewOfFile can fail with an ERROR_LOCK_VIOLATION error,
|
||||
// so like the JDK, we retry up to three times if that happens.
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (FlushViewOfFile((IntPtr)address, (IntPtr)length) != 0)
|
||||
{
|
||||
GC.KeepAlive(thisMappedByteBuffer);
|
||||
return;
|
||||
}
|
||||
const int ERROR_LOCK_VIOLATION = 33;
|
||||
if (Marshal.GetLastWin32Error() != ERROR_LOCK_VIOLATION)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if !FIRST_PASS
|
||||
throw new java.io.IOException("Flush failed");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
private static extern int FlushViewOfFile(IntPtr lpBaseAddress, IntPtr dwNumberOfBytesToFlush);
|
||||
|
||||
[DllImport("ikvm-native")]
|
||||
private static extern int ikvm_msync(IntPtr address, int size);
|
||||
}
|
154
external/ikvm/runtime/openjdk/java.security.cs
vendored
Normal file
154
external/ikvm/runtime/openjdk/java.security.cs
vendored
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
Copyright (C) 2007-2013 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jeroen Frijters
|
||||
jeroen@frijters.net
|
||||
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using IKVM.Internal;
|
||||
|
||||
static class Java_java_security_AccessController
|
||||
{
|
||||
public static object getStackAccessControlContext(java.security.AccessControlContext context, ikvm.@internal.CallerID callerID)
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return null;
|
||||
#else
|
||||
List<java.security.ProtectionDomain> array = new List<java.security.ProtectionDomain>();
|
||||
bool is_privileged = GetProtectionDomains(array, callerID, new StackTrace(1));
|
||||
if (array.Count == 0)
|
||||
{
|
||||
if (is_privileged && context == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return CreateAccessControlContext(array, is_privileged, context);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !FIRST_PASS
|
||||
private static bool GetProtectionDomains(List<java.security.ProtectionDomain> array, ikvm.@internal.CallerID callerID, StackTrace stack)
|
||||
{
|
||||
// first we have to skip all AccessController related frames, because we can be called from a doPrivileged implementation (not the privileged action)
|
||||
// in which case we should ignore the doPrivileged frame
|
||||
int skip = 0;
|
||||
for (; skip < stack.FrameCount; skip++)
|
||||
{
|
||||
Type type = stack.GetFrame(skip).GetMethod().DeclaringType;
|
||||
if (type != typeof(Java_java_security_AccessController) && type != typeof(java.security.AccessController))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
java.security.ProtectionDomain previous_protection_domain = null;
|
||||
for (int i = skip; i < stack.FrameCount; i++)
|
||||
{
|
||||
bool is_privileged = false;
|
||||
java.security.ProtectionDomain protection_domain;
|
||||
MethodBase method = stack.GetFrame(i).GetMethod();
|
||||
if (method.DeclaringType == typeof(java.security.AccessController)
|
||||
&& method.Name == "doPrivileged")
|
||||
{
|
||||
is_privileged = true;
|
||||
java.lang.Class caller = callerID.getCallerClass();
|
||||
protection_domain = caller == null ? null : Java_java_lang_Class.getProtectionDomain0(caller);
|
||||
}
|
||||
else if (Java_sun_reflect_Reflection.IsHideFromStackWalk(method))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
protection_domain = GetProtectionDomainFromType(method.DeclaringType);
|
||||
}
|
||||
|
||||
if (previous_protection_domain != protection_domain && protection_domain != null)
|
||||
{
|
||||
previous_protection_domain = protection_domain;
|
||||
array.Add(protection_domain);
|
||||
}
|
||||
|
||||
if (is_privileged)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static object CreateAccessControlContext(List<java.security.ProtectionDomain> context, bool is_privileged, java.security.AccessControlContext privileged_context)
|
||||
{
|
||||
java.security.AccessControlContext acc = new java.security.AccessControlContext(context == null || context.Count == 0 ? null : context.ToArray(), is_privileged);
|
||||
acc._privilegedContext(privileged_context);
|
||||
return acc;
|
||||
}
|
||||
|
||||
private static java.security.ProtectionDomain GetProtectionDomainFromType(Type type)
|
||||
{
|
||||
if (type == null
|
||||
|| type.Assembly == typeof(object).Assembly
|
||||
|| type.Assembly == typeof(Java_java_security_AccessController).Assembly
|
||||
|| type.Assembly == Java_java_lang_SecurityManager.jniAssembly
|
||||
|| type.Assembly == typeof(java.lang.Thread).Assembly)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(type);
|
||||
if (tw != null)
|
||||
{
|
||||
return Java_java_lang_Class.getProtectionDomain0(tw.ClassObject);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static object getInheritedAccessControlContext()
|
||||
{
|
||||
#if FIRST_PASS
|
||||
return null;
|
||||
#else
|
||||
object inheritedAccessControlContext = java.lang.Thread.currentThread().inheritedAccessControlContext;
|
||||
java.security.AccessControlContext acc = inheritedAccessControlContext as java.security.AccessControlContext;
|
||||
if (acc != null)
|
||||
{
|
||||
return acc;
|
||||
}
|
||||
java.security.AccessController.LazyContext lc = inheritedAccessControlContext as java.security.AccessController.LazyContext;
|
||||
if (lc == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<java.security.ProtectionDomain> list = new List<java.security.ProtectionDomain>();
|
||||
while (lc != null)
|
||||
{
|
||||
if (GetProtectionDomains(list, lc.callerID, lc.stackTrace))
|
||||
{
|
||||
return CreateAccessControlContext(list, true, lc.context);
|
||||
}
|
||||
lc = lc.parent;
|
||||
}
|
||||
return CreateAccessControlContext(list, false, null);
|
||||
#endif
|
||||
}
|
||||
}
|
110
external/ikvm/runtime/openjdk/sun.management.cs
vendored
110
external/ikvm/runtime/openjdk/sun.management.cs
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2011 Jeroen Frijters
|
||||
Copyright (C) 2011-2014 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -21,6 +21,7 @@
|
||||
jeroen@frijters.net
|
||||
|
||||
*/
|
||||
using System;
|
||||
#if !FIRST_PASS
|
||||
using java.lang.management;
|
||||
#endif
|
||||
@ -32,6 +33,41 @@ static class Java_sun_management_ClassLoadingImpl
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_sun_management_FileSystemImpl
|
||||
{
|
||||
public static void init0()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool isSecuritySupported0(string path)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public static bool isAccessUserOnly0(string path)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_sun_management_GcInfoBuilder
|
||||
{
|
||||
public static int getNumGcExtAttributes(object _this, object gc)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public static void fillGcAttributeInfo(object _this, object gc, int numAttributes, string[] attributeNames, char[] types, string[] descriptions)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public static object getLastGcInfo0(object _this, object gc, int numExtAtts, object[] extAttValues, char[] extAttTypes, object[] before, object[] after)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_sun_management_MemoryImpl
|
||||
{
|
||||
public static object getMemoryPools0()
|
||||
@ -67,11 +103,58 @@ static class Java_sun_management_MemoryImpl
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_sun_management_OperatingSystemImpl
|
||||
{
|
||||
public static long getCommittedVirtualMemorySize0(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static long getTotalSwapSpaceSize(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static long getFreeSwapSpaceSize(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static long getProcessCpuTime(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static long getFreePhysicalMemorySize(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static long getTotalPhysicalMemorySize(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static double getSystemCpuLoad(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static double getProcessCpuLoad(object _this)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public static void initialize()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
static class Java_sun_management_ThreadImpl
|
||||
{
|
||||
public static object getThreads()
|
||||
{
|
||||
return IKVM.NativeCode.java.lang.Thread.getThreads();
|
||||
return Java_java_lang_Thread.getThreads();
|
||||
}
|
||||
|
||||
private const int JVMTI_THREAD_STATE_ALIVE = 0x0001;
|
||||
@ -161,9 +244,28 @@ static class Java_sun_management_ThreadImpl
|
||||
#endif
|
||||
}
|
||||
|
||||
private static int GetCurrentThreadId()
|
||||
{
|
||||
#pragma warning disable 618
|
||||
// On the CLR and Mono on Windows this is the (obsolete) equivalent of kernel32!GetCurrentThreadId
|
||||
return System.AppDomain.GetCurrentThreadId();
|
||||
#pragma warning restore 618
|
||||
}
|
||||
|
||||
public static long getThreadTotalCpuTime0(long id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
if (id == 0) {
|
||||
int currentId = GetCurrentThreadId();
|
||||
System.Diagnostics.ProcessThreadCollection threads = System.Diagnostics.Process.GetCurrentProcess().Threads;
|
||||
foreach (System.Diagnostics.ProcessThread t in threads) {
|
||||
if (t.Id == currentId) {
|
||||
return (long)(t.TotalProcessorTime.Ticks * 100);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
throw new System.NotImplementedException("Only current Thread is supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void getThreadTotalCpuTime1(long[] ids, long[] result)
|
||||
@ -188,7 +290,7 @@ static class Java_sun_management_ThreadImpl
|
||||
|
||||
public static void setThreadCpuTimeEnabled0(bool enable)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
//ignoring, we need nothing to enable
|
||||
}
|
||||
|
||||
public static void setThreadAllocatedMemoryEnabled0(bool enable)
|
||||
|
Reference in New Issue
Block a user