All pastes #2129515 Raw Edit

Something

public text v1 · immutable
#2129515 ·published 2012-03-18 08:23 UTC
rendered paste body
Timothy Zhu  (2 days ago) - The reason for this error is because of a Java Reflection setting that determines when the JVM switches from using an JNI accessor to a bytecode accessor [1]. 

The default for this value, sun.reflect.inflationThreshold, is 15 [2]. After 15 reflective object construction calls, reflection will switch to using bytecode accessors. To use bytecode accessors, reflection creates a new class loader: "There are two primary reasons for creating a new loader instead of defining these bytecodes directly into the defining loader of the target class: first, it avoids any possible security risk of having these bytecodes in the same loader. Second, it allows the generated bytecodes to be unloaded earlier than would otherwise be possible, decreasing run-time footprint." [3]

However, the Nachos SecurityManager explicitly disallows all privileged actions except for a few hardcoded ones (NachosSecurityManager#checkPermission). The permission createClassLoader is not included in this list, so the NachosSecurityManager by default returns no, and the reflection call fails.

A workaround is to set the sun.reflect.inflationThreshold value to a large number. (The sun.reflect.noInflation value also exists, but it doesn't work because it causes the JVM to use bytecode accessors for everything [4]) Of course, it cannot be set in Nachos code via System#setProperty, because PropertyPermission write is also denied by default by NachosSecurityManager. It can be set on the command line via java -Dsun.reflect.inflationThreshold=XX nachos.machine.Machine, but that isn't a viable permanent solution, nor can it be done on the autograder.

Edit: The permissions required are RuntimePermission createClassLoader, RuntimePermission accessClassInPackage.sun.reflect, and java.lang.reflect.ReflectPermission suppressAccessChecks.

tl;dr: NachosSecurityManager prevents more than 15 processes from attempting to be created. Will this be addressed?

[1] http://www.ibm.com/developerworks/aix/library/j-nativememory-aix/index.html
[2] http://www.docjar.com/html/api/sun/reflect/ReflectionFactory.java.html
[3] http://www.docjar.com/docs/api/sun/reflect/ClassDefiner.html
[4] http://www.javaperformancetuning.com/news/newtips105.shtml