Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -322,16 +322,21 @@ static class Java_java_lang_Class
{
return null;
}
decl = decl.EnsureLoadable(wrapper.GetClassLoader());
if (!decl.IsAccessibleFrom(wrapper))
{
throw new IllegalAccessError(string.Format("tried to access class {0} from class {1}", decl.Name, wrapper.Name));
}
decl.Finish();
if (Array.IndexOf(decl.InnerClasses, wrapper) == -1)
TypeWrapper[] declInner = decl.InnerClasses;
for (int i = 0; i < declInner.Length; i++)
{
throw new IncompatibleClassChangeError(string.Format("{0} and {1} disagree on InnerClasses attribute", decl.Name, wrapper.Name));
if (declInner[i].Name == wrapper.Name && declInner[i].EnsureLoadable(decl.GetClassLoader()) == wrapper)
{
return decl.ClassObject;
}
}
return decl.ClassObject;
throw new IncompatibleClassChangeError(string.Format("{0} and {1} disagree on InnerClasses attribute", decl.Name, wrapper.Name));
}
catch (RetargetableJavaException x)
{
@@ -618,16 +623,13 @@ static class Java_java_lang_Class
java.lang.Class[] innerclasses = new java.lang.Class[wrappers.Length];
for (int i = 0; i < innerclasses.Length; i++)
{
if (wrappers[i].IsUnloadable)
TypeWrapper tw = wrappers[i].EnsureLoadable(wrapper.GetClassLoader());
if (!tw.IsAccessibleFrom(wrapper))
{
throw new java.lang.NoClassDefFoundError(wrappers[i].Name);
throw new IllegalAccessError(string.Format("tried to access class {0} from class {1}", tw.Name, wrapper.Name));
}
if (!wrappers[i].IsAccessibleFrom(wrapper))
{
throw new IllegalAccessError(string.Format("tried to access class {0} from class {1}", wrappers[i].Name, wrapper.Name));
}
wrappers[i].Finish();
innerclasses[i] = wrappers[i].ClassObject;
tw.Finish();
innerclasses[i] = tw.ClassObject;
}
return innerclasses;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2013 Jeroen Frijters
Copyright (C) 2007-2015 Jeroen Frijters
Copyright (C) 2009 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
@@ -134,6 +134,13 @@ static class Java_java_util_zip_ClassStubZipEntry
}
}
static class Java_java_awt_Choice
{
public static void initIDs()
{
}
}
static class Java_sun_awt_image_ByteComponentRaster
{
public static void initIDs()
@@ -162,6 +169,19 @@ static class Java_sun_awt_image_ShortComponentRaster
}
}
static class Java_sun_awt_DefaultMouseInfoPeer
{
public static int fillPointWithCoords(object _this, object point)
{
throw new NotImplementedException();
}
public static bool isWindowUnderMouse(object _this, object w)
{
throw new NotImplementedException();
}
}
static class Java_sun_awt_FontDescriptor
{
public static void initIDs()
@@ -177,6 +197,45 @@ static class Java_sun_invoke_anon_AnonymousClassLoader
}
}
static class Java_sun_invoke_util_ValueConversions
{
// called from map.xml as a replacement for Class.isInstance() in sun.invoke.util.ValueConversions.castReference()
public static bool Class_isInstance(java.lang.Class clazz, object obj)
{
TypeWrapper tw = TypeWrapper.FromClass(clazz);
// handle the type system hole that is caused by arrays being both derived from cli.System.Array and directly from java.lang.Object
return tw.IsInstance(obj) || (tw == CoreClasses.cli.System.Object.Wrapper && obj is Array);
}
}
static class Java_sun_invoke_util_VerifyAccess
{
// called from map.xml as a replacement for Class.getClassLoader() in sun.invoke.util.VerifyAccess.isTypeVisible()
public static java.lang.ClassLoader Class_getClassLoader(java.lang.Class clazz)
{
TypeWrapper tw = TypeWrapper.FromClass(clazz);
if (ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedNameFast(tw.Name) == tw)
{
// if a class is visible from the bootstrap class loader, we have to return null to allow the visibility check to succeed
return null;
}
return tw.GetClassLoader().GetJavaClassLoader();
}
}
static class Java_sun_net_PortConfig
{
public static int getLower0()
{
return 49152;
}
public static int getUpper0()
{
return 65535;
}
}
static class Java_sun_net_spi_DefaultProxySelector
{
public static bool init()
@@ -198,10 +257,10 @@ static class Java_sun_nio_fs_NetPath
#if FIRST_PASS
return null;
#else
path = java.io.FileSystem.getFileSystem().canonicalize(path);
path = java.io.DefaultFileSystem.getFileSystem().canonicalize(path);
if (VirtualFileSystem.IsVirtualFS(path))
{
if (VirtualFileSystem.CheckAccess(path, Java_java_io_Win32FileSystem.ACCESS_READ))
if (VirtualFileSystem.CheckAccess(path, Java_java_io_WinNTFileSystem.ACCESS_READ))
{
return path;
}
@@ -244,14 +303,6 @@ static class Java_sun_nio_fs_NetPath
}
}
static class Java_sun_rmi_server_MarshalInputStream
{
public static object latestUserDefinedLoader()
{
return Java_java_io_ObjectInputStream.latestUserDefinedLoader();
}
}
static class Java_sun_security_provider_NativeSeedGenerator
{
public static bool nativeGenerateSeed(byte[] result)
@@ -337,22 +388,6 @@ static class Java_com_sun_security_auth_module_NTSystem
}
}
static class Java_com_sun_security_auth_module_SolarisSystem
{
public static void getSolarisInfo(object thisObj)
{
throw new NotImplementedException();
}
}
static class Java_com_sun_security_auth_module_UnixSystem
{
public static void getUnixInfo(object thisObj)
{
throw new NotImplementedException();
}
}
static class Java_com_sun_media_sound_JDK13Services
{
public static string getDefaultProviderClassName(object deviceClass)

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2014 Jeroen Frijters
Copyright (C) 2007-2015 Jeroen Frijters
Copyright (C) 2009 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
@@ -293,6 +293,30 @@ static class Java_sun_misc_Perf
static class Java_sun_misc_Unsafe
{
public static java.lang.reflect.Field createFieldAndMakeAccessible(java.lang.Class c, string fieldName)
{
#if FIRST_PASS
return null;
#else
// we pass in ReflectAccess.class as the field type (which isn't used)
// to make Field.toString() return something "meaningful" instead of crash
java.lang.reflect.Field field = new java.lang.reflect.Field(c, fieldName, ikvm.@internal.ClassLiteral<java.lang.reflect.ReflectAccess>.Value, 0, -1, null, null);
field.@override = true;
return field;
#endif
}
public static java.lang.reflect.Field copyFieldAndMakeAccessible(java.lang.reflect.Field field)
{
#if FIRST_PASS
return null;
#else
field = new java.lang.reflect.Field(field.getDeclaringClass(), field.getName(), field.getType(), field.getModifiers() & ~java.lang.reflect.Modifier.FINAL, field._slot(), null, null);
field.@override = true;
return field;
#endif
}
private static void CheckArrayBounds(object obj, long offset, int accessLength)
{
// NOTE we rely on the fact that Buffer.ByteLength() requires a primitive array
@@ -524,8 +548,10 @@ static class Java_sun_misc_Unsafe
private delegate int CompareExchangeInt32(object obj, int value, int comparand);
private delegate long CompareExchangeInt64(object obj, long value, long comparand);
private delegate object CompareExchangeObject(object obj, object value, object comparand);
private static CompareExchangeInt32[] cacheCompareExchangeInt32 = new CompareExchangeInt32[0];
private static CompareExchangeInt64[] cacheCompareExchangeInt64 = new CompareExchangeInt64[0];
private static CompareExchangeObject[] cacheCompareExchangeObject = new CompareExchangeObject[0];
private static void InterlockedResize<T>(ref T[] array, int newSize)
{
@@ -549,16 +575,44 @@ static class Java_sun_misc_Unsafe
private static Delegate CreateCompareExchange(long fieldOffset)
{
FieldInfo field = GetFieldInfo(fieldOffset);
DynamicMethod dm = new DynamicMethod("CompareExchange", field.FieldType, new Type[] { typeof(object), field.FieldType, field.FieldType }, field.DeclaringType);
bool primitive = field.FieldType.IsPrimitive;
Type signatureType = primitive ? field.FieldType : typeof(object);
MethodInfo compareExchange;
Type delegateType;
if (signatureType == typeof(int))
{
compareExchange = InterlockedMethods.CompareExchangeInt32;
delegateType = typeof(CompareExchangeInt32);
}
else if (signatureType == typeof(long))
{
compareExchange = InterlockedMethods.CompareExchangeInt64;
delegateType = typeof(CompareExchangeInt64);
}
else
{
compareExchange = InterlockedMethods.CompareExchangeOfT.MakeGenericMethod(field.FieldType);
delegateType = typeof(CompareExchangeObject);
}
DynamicMethod dm = new DynamicMethod("CompareExchange", signatureType, new Type[] { typeof(object), signatureType, signatureType }, field.DeclaringType);
ILGenerator ilgen = dm.GetILGenerator();
// note that we don't bother will special casing static fields, because it is legal to use ldflda on a static field
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Castclass, field.DeclaringType);
ilgen.Emit(OpCodes.Ldflda, field);
ilgen.Emit(OpCodes.Ldarg_1);
if (!primitive)
{
ilgen.Emit(OpCodes.Castclass, field.FieldType);
}
ilgen.Emit(OpCodes.Ldarg_2);
ilgen.Emit(OpCodes.Call, typeof(Interlocked).GetMethod("CompareExchange", new Type[] { field.FieldType.MakeByRefType(), field.FieldType, field.FieldType }));
if (!primitive)
{
ilgen.Emit(OpCodes.Castclass, field.FieldType);
}
ilgen.Emit(OpCodes.Call, compareExchange);
ilgen.Emit(OpCodes.Ret);
return dm.CreateDelegate(field.FieldType == typeof(int) ? typeof(CompareExchangeInt32) : typeof(CompareExchangeInt64));
return dm.CreateDelegate(delegateType);
}
private static FieldInfo GetFieldInfo(long offset)
@@ -583,8 +637,13 @@ static class Java_sun_misc_Unsafe
}
else
{
if (offset >= cacheCompareExchangeObject.Length || cacheCompareExchangeObject[offset] == null)
{
InterlockedResize(ref cacheCompareExchangeObject, (int)offset + 1);
cacheCompareExchangeObject[offset] = (CompareExchangeObject)CreateCompareExchange(offset);
}
Stats.Log("compareAndSwapObject.", offset);
return Atomic.CompareExchange(obj, new FieldInfo[] { GetFieldInfo(offset) }, update, expect) == expect;
return cacheCompareExchangeObject[offset](obj, update, expect) == expect;
}
#endif
}
@@ -594,12 +653,6 @@ static class Java_sun_misc_Unsafe
// NOTE we don't care that we keep the Type alive, because Unsafe should only be used inside the core class libraries
private static Dictionary<Type, Atomic> impls = new Dictionary<Type, Atomic>();
internal static object CompareExchange(object obj, FieldInfo[] field, object value, object comparand)
{
TypedReference tr = TypedReference.MakeTypedReference(obj, field);
return GetImpl(__reftype(tr)).CompareExchangeImpl(tr, value, comparand);
}
internal static object CompareExchange(object[] array, int index, object value, object comparand)
{
return GetImpl(array.GetType().GetElementType()).CompareExchangeImpl(array, index, value, comparand);
@@ -619,17 +672,11 @@ static class Java_sun_misc_Unsafe
return impl;
}
protected abstract object CompareExchangeImpl(TypedReference tr, object value, object comparand);
protected abstract object CompareExchangeImpl(object[] array, int index, object value, object comparand);
sealed class Impl<T> : Atomic
where T : class
{
protected override object CompareExchangeImpl(TypedReference tr, object value, object comparand)
{
return Interlocked.CompareExchange(ref __refvalue(tr, T), (T)value, (T)comparand);
}
protected override object CompareExchangeImpl(object[] array, int index, object value, object comparand)
{
return Interlocked.CompareExchange<T>(ref ((T[])array)[index], (T)value, (T)comparand);

View File

@@ -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
@@ -32,6 +32,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Security;
using IKVM.Internal;
using IKVM.Attributes;
namespace IKVM.Internal
{
@@ -42,48 +43,41 @@ namespace IKVM.Internal
java.lang.IllegalArgumentException SetIllegalArgumentException(object obj);
}
#endif
sealed class State
{
internal int Value;
}
}
static class Java_sun_reflect_Reflection
{
#if CLASSGC
sealed class State
{
internal HideFromJavaFlags Value;
internal volatile bool HasValue;
}
private static readonly ConditionalWeakTable<MethodBase, State> isHideFromJavaCache = new ConditionalWeakTable<MethodBase, State>();
internal static bool IsHideFromJava(MethodBase mb)
{
State state = isHideFromJavaCache.GetValue(mb, delegate { return new State(); });
if (state.Value == 0)
{
state.Value = IsHideFromJavaImpl(mb);
}
return state.Value == 1;
}
private static int IsHideFromJavaImpl(MethodBase mb)
internal static HideFromJavaFlags GetHideFromJavaFlags(MethodBase mb)
{
if (mb.Name.StartsWith("__<", StringComparison.Ordinal))
{
return 1;
return HideFromJavaFlags.All;
}
if (mb.IsDefined(typeof(IKVM.Attributes.HideFromJavaAttribute), false) || mb.IsDefined(typeof(IKVM.Attributes.HideFromReflectionAttribute), false))
State state = isHideFromJavaCache.GetValue(mb, delegate { return new State(); });
if (!state.HasValue)
{
return 1;
state.Value = AttributeHelper.GetHideFromJavaFlags(mb);
state.HasValue = true;
}
return 2;
return state.Value;
}
#else
private static readonly Dictionary<RuntimeMethodHandle, bool> isHideFromJavaCache = new Dictionary<RuntimeMethodHandle, bool>();
private static readonly Dictionary<RuntimeMethodHandle, HideFromJavaFlags> isHideFromJavaCache = new Dictionary<RuntimeMethodHandle, HideFromJavaFlags>();
internal static bool IsHideFromJava(MethodBase mb)
internal static HideFromJavaFlags GetHideFromJavaFlags(MethodBase mb)
{
if (mb.Name.StartsWith("__<", StringComparison.Ordinal))
{
return true;
return HideFromJavaFlags.All;
}
RuntimeMethodHandle handle;
try
@@ -93,66 +87,83 @@ static class Java_sun_reflect_Reflection
catch (InvalidOperationException)
{
// DynamicMethods don't have a RuntimeMethodHandle and we always want to hide them anyway
return true;
return HideFromJavaFlags.All;
}
catch (NotSupportedException)
{
// DynamicMethods don't have a RuntimeMethodHandle and we always want to hide them anyway
return true;
return HideFromJavaFlags.All;
}
lock (isHideFromJavaCache)
{
bool cached;
HideFromJavaFlags cached;
if (isHideFromJavaCache.TryGetValue(handle, out cached))
{
return cached;
}
}
bool isHide = mb.IsDefined(typeof(IKVM.Attributes.HideFromJavaAttribute), false) || mb.IsDefined(typeof(IKVM.Attributes.HideFromReflectionAttribute), false);
HideFromJavaFlags flags = AttributeHelper.GetHideFromJavaFlags(mb);
lock (isHideFromJavaCache)
{
isHideFromJavaCache[handle] = isHide;
isHideFromJavaCache[handle] = flags;
}
return isHide;
return flags;
}
#endif
// NOTE this method is hooked up explicitly through map.xml to prevent inlining of the native stub
// and tail-call optimization in the native stub.
public static object getCallerClass(int realFramesToSkip)
internal static bool IsHideFromStackWalk(MethodBase mb)
{
Type type = mb.DeclaringType;
return type == null
|| type.Assembly == typeof(object).Assembly
|| type.Assembly == typeof(Java_sun_reflect_Reflection).Assembly
|| type.Assembly == Java_java_lang_SecurityManager.jniAssembly
|| type == typeof(java.lang.reflect.Method)
|| type == typeof(java.lang.reflect.Constructor)
|| (GetHideFromJavaFlags(mb) & HideFromJavaFlags.StackWalk) != 0
;
}
public static java.lang.Class getCallerClass()
{
#if FIRST_PASS
return null;
#else
int i = 3;
if (realFramesToSkip <= 1)
throw new java.lang.InternalError("CallerSensitive annotation expected at frame 1");
#endif
}
// NOTE this method is hooked up explicitly through map.xml to prevent inlining of the native stub
// and tail-call optimization in the native stub.
public static java.lang.Class getCallerClass(int realFramesToSkip)
{
#if FIRST_PASS
return null;
#else
if (realFramesToSkip <= 0)
{
i = 1;
realFramesToSkip = Math.Max(realFramesToSkip + 2, 2);
return ikvm.@internal.ClassLiteral<sun.reflect.Reflection>.Value;
}
realFramesToSkip--;
for (; ; )
for (int i = 2; ; )
{
MethodBase method = new StackFrame(i++, false).GetMethod();
if (method == null)
{
return null;
}
Type type = method.DeclaringType;
// NOTE these checks should be the same as the ones in SecurityManager.getClassContext
if (IsHideFromJava(method)
|| type == null
|| type.Assembly == typeof(object).Assembly
|| type.Assembly == typeof(Java_sun_reflect_Reflection).Assembly
|| type.Assembly == Java_java_lang_SecurityManager.jniAssembly
|| type == typeof(java.lang.reflect.Method)
|| type == typeof(java.lang.reflect.Constructor))
if (IsHideFromStackWalk(method))
{
continue;
}
// HACK we skip HideFromJavaFlags.StackTrace too because we want to skip the LambdaForm methods
// that are used by late binding
if ((GetHideFromJavaFlags(method) & HideFromJavaFlags.StackTrace) != 0)
{
continue;
}
if (--realFramesToSkip == 0)
{
return ClassLoaderWrapper.GetWrapperFromType(type).ClassObject;
return ClassLoaderWrapper.GetWrapperFromType(method.DeclaringType).ClassObject;
}
}
#endif
@@ -368,7 +379,7 @@ static class Java_sun_reflect_ReflectionFactory
internal SerializationConstructorAccessorImpl(java.lang.reflect.Constructor constructorToCall, java.lang.Class classToInstantiate)
{
this.type = TypeWrapper.FromClass(classToInstantiate).TypeAsBaseType;
MethodWrapper mw = MethodWrapper.FromConstructor(constructorToCall);
MethodWrapper mw = MethodWrapper.FromExecutable(constructorToCall);
if (mw.DeclaringType != CoreClasses.java.lang.Object.Wrapper)
{
this.mw = mw;
@@ -804,7 +815,7 @@ static class Java_sun_reflect_ReflectionFactory
internal FastConstructorAccessorImpl(java.lang.reflect.Constructor constructor)
{
MethodWrapper mw = MethodWrapper.FromConstructor(constructor);
MethodWrapper mw = MethodWrapper.FromExecutable(constructor);
TypeWrapper[] parameters;
try
{
@@ -925,7 +936,7 @@ static class Java_sun_reflect_ReflectionFactory
internal FastSerializationConstructorAccessorImpl(java.lang.reflect.Constructor constructorToCall, java.lang.Class classToInstantiate)
{
MethodWrapper constructor = MethodWrapper.FromConstructor(constructorToCall);
MethodWrapper constructor = MethodWrapper.FromExecutable(constructorToCall);
if (constructor.GetParameters().Length != 0)
{
throw new NotImplementedException("Serialization constructor cannot have parameters");
@@ -1028,10 +1039,10 @@ static class Java_sun_reflect_ReflectionFactory
}
}
private FieldAccessorImplBase(FieldWrapper fw, bool overrideAccessCheck)
private FieldAccessorImplBase(FieldWrapper fw, bool isFinal)
{
this.fw = fw;
isFinal = (!overrideAccessCheck || fw.IsStatic) && fw.IsFinal;
this.isFinal = isFinal;
}
private string GetQualifiedFieldName()
@@ -1041,7 +1052,9 @@ static class Java_sun_reflect_ReflectionFactory
private string GetFieldTypeName()
{
return fw.FieldTypeWrapper.ClassObject.getName();
return fw.FieldTypeWrapper.IsPrimitive
? fw.FieldTypeWrapper.ClassObject.getName()
: fw.FieldTypeWrapper.Name;
}
public java.lang.IllegalArgumentException GetIllegalArgumentException(object obj)
@@ -1191,8 +1204,8 @@ static class Java_sun_reflect_ReflectionFactory
protected Setter setter = initialSetter;
protected Getter getter = initialGetter;
internal FieldAccessor(FieldWrapper fw, bool overrideAccessCheck)
: base(fw, overrideAccessCheck)
internal FieldAccessor(FieldWrapper fw, bool isFinal)
: base(fw, isFinal)
{
if (!IsSlowPathCompatible(fw))
{
@@ -1321,8 +1334,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class ByteField : FieldAccessor<byte>
{
internal ByteField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal ByteField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1397,8 +1410,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class BooleanField : FieldAccessor<bool>
{
internal BooleanField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal BooleanField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1448,8 +1461,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class CharField : FieldAccessor<char>
{
internal CharField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal CharField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1518,8 +1531,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class ShortField : FieldAccessor<short>
{
internal ShortField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal ShortField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1594,8 +1607,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class IntField : FieldAccessor<int>
{
internal IntField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal IntField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1678,8 +1691,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class FloatField : FieldAccessor<float>
{
internal FloatField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal FloatField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1764,8 +1777,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class LongField : FieldAccessor<long>
{
internal LongField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal LongField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1849,8 +1862,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class DoubleField : FieldAccessor<double>
{
internal DoubleField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal DoubleField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -1936,8 +1949,8 @@ static class Java_sun_reflect_ReflectionFactory
private sealed class ObjectField : FieldAccessor<object>
{
internal ObjectField(FieldWrapper field, bool overrideAccessCheck)
: base(field, overrideAccessCheck)
internal ObjectField(FieldWrapper field, bool isFinal)
: base(field, isFinal)
{
}
@@ -2095,48 +2108,48 @@ static class Java_sun_reflect_ReflectionFactory
}
#endif // !NO_REF_EMIT
internal static FieldAccessorImplBase Create(FieldWrapper field, bool overrideAccessCheck)
internal static FieldAccessorImplBase Create(FieldWrapper field, bool isFinal)
{
TypeWrapper type = field.FieldTypeWrapper;
if (type.IsPrimitive)
{
if (type == PrimitiveTypeWrapper.BYTE)
{
return new ByteField(field, overrideAccessCheck);
return new ByteField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.BOOLEAN)
{
return new BooleanField(field, overrideAccessCheck);
return new BooleanField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.CHAR)
{
return new CharField(field, overrideAccessCheck);
return new CharField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.SHORT)
{
return new ShortField(field, overrideAccessCheck);
return new ShortField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.INT)
{
return new IntField(field, overrideAccessCheck);
return new IntField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.FLOAT)
{
return new FloatField(field, overrideAccessCheck);
return new FloatField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.LONG)
{
return new LongField(field, overrideAccessCheck);
return new LongField(field, isFinal);
}
if (type == PrimitiveTypeWrapper.DOUBLE)
{
return new DoubleField(field, overrideAccessCheck);
return new DoubleField(field, isFinal);
}
throw new InvalidOperationException("field type: " + type);
}
else
{
return new ObjectField(field, overrideAccessCheck);
return new ObjectField(field, isFinal);
}
}
}
@@ -2147,14 +2160,18 @@ static class Java_sun_reflect_ReflectionFactory
#if FIRST_PASS
return null;
#else
return FieldAccessorImplBase.Create(FieldWrapper.FromField(field), overrideAccessCheck);
// we look at the modifiers of the Field object to allow Unsafe to give us a fake Field take doesn't have the final flag set
int modifiers = field.getModifiers();
bool isStatic = java.lang.reflect.Modifier.isStatic(modifiers);
bool isFinal = java.lang.reflect.Modifier.isFinal(modifiers);
return FieldAccessorImplBase.Create(FieldWrapper.FromField(field), isFinal && (!overrideAccessCheck || isStatic));
#endif
}
#if !FIRST_PASS
internal static sun.reflect.FieldAccessor NewFieldAccessorJNI(FieldWrapper field)
{
return FieldAccessorImplBase.Create(field, true);
return FieldAccessorImplBase.Create(field, false);
}
#endif
@@ -2163,7 +2180,7 @@ static class Java_sun_reflect_ReflectionFactory
#if FIRST_PASS
return null;
#else
MethodWrapper mw = MethodWrapper.FromMethod(method);
MethodWrapper mw = MethodWrapper.FromExecutable(method);
#if !NO_REF_EMIT
if (!mw.IsDynamicOnly)
{
@@ -2179,7 +2196,7 @@ static class Java_sun_reflect_ReflectionFactory
#if FIRST_PASS
return null;
#else
MethodWrapper mw = MethodWrapper.FromConstructor(constructor);
MethodWrapper mw = MethodWrapper.FromExecutable(constructor);
if (ActivatorConstructorAccessor.IsSuitable(mw))
{
// we special case public default constructors, because in that case using Activator.CreateInstance()