Signature: (Ljava/security/PrivilegedAction;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2
(JNIEnv *env, jclass cls, jobject action)
{
return JVM_DoPrivileged(env, cls, action, NULL, JNI_FALSE);
}[/code]
hotspot\src\share\vm\prims\jvm.cpp
[code="c++"]JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
JVMWrapper("JVM_DoPrivileged");
if (action == NULL) {
THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action");
}
// Stack allocated list of privileged stack elements
PrivilegedElement pi;
// Check that action object understands "Object run()"
Handle object (THREAD, JNIHandles::resolve(action));
// get run() method
methodOop m_oop = Klass::cast(object->klass())->uncached_lookup_method(
vmSymbols::run_method_name(),
vmSymbols::void_object_signature());
methodHandle m (THREAD, m_oop);
if (m.is_null() || !m->is_method() || !methodOop(m())->is_public() || methodOop(m())->is_static()) {
THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
}
// Compute the frame initiating the do privileged operation and setup the privileged stack
vframeStream vfst(thread);
vfst.security_get_caller_frame(1);
if (!vfst.at_end()) {
pi.initialize(&vfst, JNIHandles::resolve(context), thread->privileged_stack_top(), CHECK_NULL);
thread->set_privileged_stack_top(&pi);
}
// invoke the Object run() in the action object. We cannot use call_interface here, since the static type
// is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
Handle pending_exception;
JavaValue result(T_OBJECT);
JavaCallArguments args(object);
JavaCalls::call(&result, m, &args, THREAD);
// done with action, remove ourselves from the list
if (!vfst.at_end()) {
assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
thread->set_privileged_stack_top(thread->privileged_stack_top()->next());
}
if (HAS_PENDING_EXCEPTION) {
pending_exception = Handle(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
if ( pending_exception->is_a(SystemDictionary::exception_klass()) &&
!pending_exception->is_a(SystemDictionary::runtime_exception_klass())) {
// Throw a java.security.PrivilegedActionException(Exception e) exception
JavaCallArguments args(pending_exception);
THROW_ARG_0(vmSymbolHandles::java_security_PrivilegedActionException(),
vmSymbolHandles::exception_void_signature(),
&args);
}
}
if (pending_exception.not_null()) THROW_OOP_0(pending_exception());
return JNIHandles::make_local(env, (oop) result.get_jobject());
JVM_END[/code]
这些源码可以从Sun的官网获取,http://download.java.net/jdk6/source/ ,也可以下载OpenJDK版,http://download.java.net/openjdk/jdk6/