You've already forked linux-packaging-mono
Imported Upstream version 4.2.1.36
Former-commit-id: fb75898888a02f4d3a74cf0a5b841681bc4c7fa8
This commit is contained in:
committed by
Jo Shields
parent
9668de7cb8
commit
dd547c45d4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@@ -34,7 +34,6 @@
|
||||
package sun.reflect;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -47,17 +46,18 @@ public class Reflection {
|
||||
view, where they are sensitive or they may contain VM-internal objects.
|
||||
These Maps are updated very rarely. Rather than synchronize on
|
||||
each access, we use copy-on-write */
|
||||
private static volatile Map<Class,String[]> fieldFilterMap;
|
||||
private static volatile Map<Class,String[]> methodFilterMap;
|
||||
private static volatile Map<Class<?>,String[]> fieldFilterMap;
|
||||
private static volatile Map<Class<?>,String[]> methodFilterMap;
|
||||
|
||||
static {
|
||||
Map<Class,String[]> map = new HashMap<Class,String[]>();
|
||||
Map<Class<?>,String[]> map = new HashMap<Class<?>,String[]>();
|
||||
map.put(Reflection.class,
|
||||
new String[] {"fieldFilterMap", "methodFilterMap"});
|
||||
map.put(System.class, new String[] {"security"});
|
||||
map.put(Class.class, new String[] {"classLoader"});
|
||||
fieldFilterMap = map;
|
||||
|
||||
methodFilterMap = new HashMap<Class,String[]>();
|
||||
methodFilterMap = new HashMap<>();
|
||||
// [IKVM] to avoid initialization order issues, we actually add
|
||||
// Unsafe.getUnsafe() here, instead of in Unsafe's class initializer
|
||||
methodFilterMap.put(sun.misc.Unsafe.class, new String[] {"getUnsafe"});
|
||||
@@ -67,21 +67,15 @@ public class Reflection {
|
||||
ignoring frames associated with java.lang.reflect.Method.invoke()
|
||||
and its implementation. */
|
||||
@CallerSensitive
|
||||
public static Class getCallerClass() {
|
||||
return getCallerClass(2);
|
||||
}
|
||||
public static native Class<?> getCallerClass();
|
||||
|
||||
/** Returns the class of the method <code>realFramesToSkip</code>
|
||||
frames up the stack (zero-based), ignoring frames associated
|
||||
with java.lang.reflect.Method.invoke() and its implementation.
|
||||
The first frame is that associated with this method, so
|
||||
<code>getCallerClass(0)</code> returns the Class object for
|
||||
sun.reflect.Reflection. Frames associated with
|
||||
java.lang.reflect.Method.invoke() and its implementation are
|
||||
completely ignored and do not count toward the number of "real"
|
||||
frames skipped. */
|
||||
@CallerSensitive
|
||||
public static native Class getCallerClass(int realFramesToSkip);
|
||||
/**
|
||||
* @deprecated This method will be removed in JDK 9.
|
||||
* This method is a private JDK API and retained temporarily for
|
||||
* existing code to run until a replacement API is defined.
|
||||
*/
|
||||
@Deprecated
|
||||
public static native Class<?> getCallerClass(int depth);
|
||||
|
||||
/** Retrieves the access flags written to the class file. For
|
||||
inner classes these flags may differ from those returned by
|
||||
@@ -91,18 +85,18 @@ public class Reflection {
|
||||
to compatibility reasons; see 4471811. Only the values of the
|
||||
low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
|
||||
valid. */
|
||||
private static native int getClassAccessFlags(Class c);
|
||||
public static native int getClassAccessFlags(Class<?> c);
|
||||
|
||||
/** A quick "fast-path" check to try to avoid getCallerClass()
|
||||
calls. */
|
||||
public static boolean quickCheckMemberAccess(Class memberClass,
|
||||
public static boolean quickCheckMemberAccess(Class<?> memberClass,
|
||||
int modifiers)
|
||||
{
|
||||
return Modifier.isPublic(getClassAccessFlags(memberClass) & modifiers);
|
||||
}
|
||||
|
||||
public static void ensureMemberAccess(Class currentClass,
|
||||
Class memberClass,
|
||||
public static void ensureMemberAccess(Class<?> currentClass,
|
||||
Class<?> memberClass,
|
||||
Object target,
|
||||
int modifiers)
|
||||
throws IllegalAccessException
|
||||
@@ -124,13 +118,13 @@ public class Reflection {
|
||||
/*IKVM*/
|
||||
private static native boolean checkInternalAccess(Class currentClass, Class memberClass);
|
||||
|
||||
public static boolean verifyMemberAccess(Class currentClass,
|
||||
public static boolean verifyMemberAccess(Class<?> currentClass,
|
||||
// Declaring class of field
|
||||
// or method
|
||||
Class memberClass,
|
||||
Class<?> memberClass,
|
||||
// May be NULL in case of statics
|
||||
Object target,
|
||||
int modifiers)
|
||||
Object target,
|
||||
int modifiers)
|
||||
{
|
||||
// Verify that currentClass can access a field, method, or
|
||||
// constructor of memberClass, where that member's access bits are
|
||||
@@ -192,7 +186,7 @@ public class Reflection {
|
||||
|
||||
if (Modifier.isProtected(modifiers)) {
|
||||
// Additional test for protected members: JLS 6.6.2
|
||||
Class targetClass = (target == null ? memberClass : target.getClass());
|
||||
Class<?> targetClass = (target == null ? memberClass : target.getClass());
|
||||
if (targetClass != currentClass) {
|
||||
if (!gotIsSameClassPackage) {
|
||||
isSameClassPackage = isSameClassPackage(currentClass, memberClass);
|
||||
@@ -209,7 +203,7 @@ public class Reflection {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isSameClassPackage(Class c1, Class c2) {
|
||||
private static boolean isSameClassPackage(Class<?> c1, Class<?> c2) {
|
||||
return isSameClassPackage(c1.getClassLoader(), c1.getName(),
|
||||
c2.getClassLoader(), c2.getName());
|
||||
}
|
||||
@@ -264,8 +258,8 @@ public class Reflection {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isSubclassOf(Class queryClass,
|
||||
Class ofClass)
|
||||
static boolean isSubclassOf(Class<?> queryClass,
|
||||
Class<?> ofClass)
|
||||
{
|
||||
while (queryClass != null) {
|
||||
if (queryClass == ofClass) {
|
||||
@@ -277,31 +271,31 @@ public class Reflection {
|
||||
}
|
||||
|
||||
// fieldNames must contain only interned Strings
|
||||
public static synchronized void registerFieldsToFilter(Class containingClass,
|
||||
public static synchronized void registerFieldsToFilter(Class<?> containingClass,
|
||||
String ... fieldNames) {
|
||||
fieldFilterMap =
|
||||
registerFilter(fieldFilterMap, containingClass, fieldNames);
|
||||
}
|
||||
|
||||
// methodNames must contain only interned Strings
|
||||
public static synchronized void registerMethodsToFilter(Class containingClass,
|
||||
public static synchronized void registerMethodsToFilter(Class<?> containingClass,
|
||||
String ... methodNames) {
|
||||
methodFilterMap =
|
||||
registerFilter(methodFilterMap, containingClass, methodNames);
|
||||
}
|
||||
|
||||
private static Map<Class,String[]> registerFilter(Map<Class,String[]> map,
|
||||
Class containingClass, String ... names) {
|
||||
private static Map<Class<?>,String[]> registerFilter(Map<Class<?>,String[]> map,
|
||||
Class<?> containingClass, String ... names) {
|
||||
if (map.get(containingClass) != null) {
|
||||
throw new IllegalArgumentException
|
||||
("Filter already registered: " + containingClass);
|
||||
}
|
||||
map = new HashMap<Class,String[]>(map);
|
||||
map = new HashMap<Class<?>,String[]>(map);
|
||||
map.put(containingClass, names);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Field[] filterFields(Class containingClass,
|
||||
public static Field[] filterFields(Class<?> containingClass,
|
||||
Field[] fields) {
|
||||
if (fieldFilterMap == null) {
|
||||
// Bootstrapping
|
||||
@@ -310,7 +304,7 @@ public class Reflection {
|
||||
return (Field[])filter(fields, fieldFilterMap.get(containingClass));
|
||||
}
|
||||
|
||||
public static Method[] filterMethods(Class containingClass, Method[] methods) {
|
||||
public static Method[] filterMethods(Class<?> containingClass, Method[] methods) {
|
||||
if (methodFilterMap == null) {
|
||||
// Bootstrapping
|
||||
return methods;
|
||||
@@ -352,4 +346,27 @@ public class Reflection {
|
||||
}
|
||||
return newMembers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the given method is caller-sensitive and the declaring class
|
||||
* is defined by either the bootstrap class loader or extension class loader.
|
||||
*/
|
||||
public static boolean isCallerSensitive(Method m) {
|
||||
final ClassLoader loader = m.getDeclaringClass().getClassLoader();
|
||||
if (sun.misc.VM.isSystemDomainLoader(loader) || isExtClassLoader(loader)) {
|
||||
return m.isAnnotationPresent(CallerSensitive.class);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isExtClassLoader(ClassLoader loader) {
|
||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
while (cl != null) {
|
||||
if (cl.getParent() == null && cl == loader) {
|
||||
return true;
|
||||
}
|
||||
cl = cl.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user