Commit e5a8980b by Andrew Haley Committed by Andrew Haley

natVMSecurityManager.cc (getClassContext): Add new arg: klass.

2005-03-17  Andrew Haley  <aph@redhat.com>

	* java/lang/natVMSecurityManager.cc (getClassContext): Add new
	arg: klass.
	Pass klass to _Jv_StackTrace::GetClassContext().
	* java/lang/ClassLoader.java (getParent): Pass class to
	VMSecurityManager.getClassContext()
	(getSystemClassLoader): Likewise.
	* java/lang/Package.java (getPackage): Likewise.
	(getPackages): Likewise.
	* java/lang/SecurityManager.java (getClassContext): Likewise.
	(currentClassLoader): Likewise.
	* java/lang/VMSecurityManager.java: (getClassContext): Likewise.
	(currentClassLoader) Add new arg: caller.
	Pass caller to VMSecurityManager.getClassContext.

	* stacktrace.cc (GetClassContext): Correct calculation of
	jframe_count.

	* boehm.cc (_Jv_MarkObj): (_Jv_MarkObj): Mark
	im->source_file_name.

From-SVN: r96803
parent 21e01bf1
2005-03-17 Andrew Haley <aph@redhat.com>
* java/lang/natVMSecurityManager.cc (getClassContext): Add new
arg: klass.
Pass klass to _Jv_StackTrace::GetClassContext().
* java/lang/ClassLoader.java (getParent): Pass class to
VMSecurityManager.getClassContext()
(getSystemClassLoader): Likewise.
* java/lang/Package.java (getPackage): Likewise.
(getPackages): Likewise.
* java/lang/SecurityManager.java (getClassContext): Likewise.
(currentClassLoader): Likewise.
* java/lang/VMSecurityManager.java: (getClassContext): Likewise.
(currentClassLoader) Add new arg: caller.
Pass caller to VMSecurityManager.getClassContext.
* stacktrace.cc (GetClassContext): Correct calculation of
jframe_count.
* boehm.cc (_Jv_MarkObj): (_Jv_MarkObj): Mark
im->source_file_name.
2005-03-16 Andrew Haley <aph@redhat.com> 2005-03-16 Andrew Haley <aph@redhat.com>
* boehm.cc (_Jv_MarkObj): Mark the interpreted method line_table. * boehm.cc (_Jv_MarkObj): Mark the interpreted method line_table.
......
...@@ -248,6 +248,9 @@ _Jv_MarkObj (void *addr, void *msp, void *msl, void *env) ...@@ -248,6 +248,9 @@ _Jv_MarkObj (void *addr, void *msp, void *msl, void *env)
p = (GC_PTR) ic->interpreted_methods; p = (GC_PTR) ic->interpreted_methods;
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic); MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
p = (GC_PTR) ic->source_file_name;
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
for (int i = 0; i < c->method_count; i++) for (int i = 0; i < c->method_count; i++)
{ {
// The interpreter installs a heap-allocated trampoline // The interpreter installs a heap-allocated trampoline
......
...@@ -486,7 +486,7 @@ public abstract class ClassLoader ...@@ -486,7 +486,7 @@ public abstract class ClassLoader
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
{ {
Class c = VMSecurityManager.getClassContext()[1]; Class c = VMSecurityManager.getClassContext(ClassLoader.class)[1];
ClassLoader cl = c.getClassLoader(); ClassLoader cl = c.getClassLoader();
if (cl != null && ! cl.isAncestorOf(this)) if (cl != null && ! cl.isAncestorOf(this))
sm.checkPermission(new RuntimePermission("getClassLoader")); sm.checkPermission(new RuntimePermission("getClassLoader"));
...@@ -729,7 +729,7 @@ public abstract class ClassLoader ...@@ -729,7 +729,7 @@ public abstract class ClassLoader
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
{ {
Class c = VMSecurityManager.getClassContext()[1]; Class c = VMSecurityManager.getClassContext(ClassLoader.class)[1];
ClassLoader cl = c.getClassLoader(); ClassLoader cl = c.getClassLoader();
if (cl != null && cl != systemClassLoader) if (cl != null && cl != systemClassLoader)
sm.checkPermission(new RuntimePermission("getClassLoader")); sm.checkPermission(new RuntimePermission("getClassLoader"));
......
...@@ -273,7 +273,7 @@ public class Package ...@@ -273,7 +273,7 @@ public class Package
public static Package getPackage(String name) public static Package getPackage(String name)
{ {
// Get the caller's classloader // Get the caller's classloader
ClassLoader cl = VMSecurityManager.currentClassLoader(); ClassLoader cl = VMSecurityManager.currentClassLoader(Package.class);
return cl != null ? cl.getPackage(name) : VMClassLoader.getPackage(name); return cl != null ? cl.getPackage(name) : VMClassLoader.getPackage(name);
} }
...@@ -286,7 +286,7 @@ public class Package ...@@ -286,7 +286,7 @@ public class Package
public static Package[] getPackages() public static Package[] getPackages()
{ {
// Get the caller's classloader // Get the caller's classloader
Class c = VMSecurityManager.getClassContext()[1]; Class c = VMSecurityManager.getClassContext(Package.class)[1];
ClassLoader cl = c.getClassLoader(); ClassLoader cl = c.getClassLoader();
return cl != null ? cl.getPackages() : VMClassLoader.getPackages(); return cl != null ? cl.getPackages() : VMClassLoader.getPackages();
} }
......
...@@ -167,7 +167,7 @@ public class SecurityManager ...@@ -167,7 +167,7 @@ public class SecurityManager
*/ */
protected Class[] getClassContext() protected Class[] getClassContext()
{ {
return VMSecurityManager.getClassContext(); return VMSecurityManager.getClassContext(SecurityManager.class);
} }
/** /**
...@@ -189,7 +189,7 @@ public class SecurityManager ...@@ -189,7 +189,7 @@ public class SecurityManager
*/ */
protected ClassLoader currentClassLoader() protected ClassLoader currentClassLoader()
{ {
return VMSecurityManager.currentClassLoader(); return VMSecurityManager.currentClassLoader(SecurityManager.class);
} }
/** /**
......
...@@ -43,19 +43,19 @@ class VMSecurityManager ...@@ -43,19 +43,19 @@ class VMSecurityManager
** @return an array containing all the methods on classes ** @return an array containing all the methods on classes
** on the Java execution stack. ** on the Java execution stack.
**/ **/
static native Class[] getClassContext(); static native Class[] getClassContext(Class caller);
/** Get the current ClassLoader--the one nearest to the /** Get the current ClassLoader--the one nearest to the
** top of the stack. ** top of the stack.
** @return the current ClassLoader. ** @return the current ClassLoader.
**/ **/
static ClassLoader currentClassLoader() static ClassLoader currentClassLoader(Class caller)
{ {
// The docs above are wrong. See the online docs. // The docs above are wrong. See the online docs.
// FIXME this implementation is a bit wrong too -- the docs say we // FIXME this implementation is a bit wrong too -- the docs say we
// must also consider ancestors of the system class loader. // must also consider ancestors of the system class loader.
ClassLoader systemClassLoader = VMClassLoader.getSystemClassLoader(); ClassLoader systemClassLoader = VMClassLoader.getSystemClassLoader();
Class[] classStack = getClassContext (); Class[] classStack = getClassContext (caller);
for (int i = 0; i < classStack.length; i++) for (int i = 0; i < classStack.length; i++)
{ {
ClassLoader loader = classStack[i].getClassLoader(); ClassLoader loader = classStack[i].getClassLoader();
......
...@@ -20,10 +20,10 @@ details. */ ...@@ -20,10 +20,10 @@ details. */
#include <java/lang/Class.h> #include <java/lang/Class.h>
JArray<jclass> * JArray<jclass> *
java::lang::VMSecurityManager::getClassContext () java::lang::VMSecurityManager::getClassContext (jclass klass)
{ {
JArray<jclass> *result = JArray<jclass> *result =
_Jv_StackTrace::GetClassContext (&SecurityManager::class$); _Jv_StackTrace::GetClassContext (klass);
return result; return result;
} }
...@@ -464,19 +464,17 @@ _Jv_StackTrace::GetClassContext (jclass checkClass) ...@@ -464,19 +464,17 @@ _Jv_StackTrace::GetClassContext (jclass checkClass)
_Jv_StackFrame *frame = &state.frames[i]; _Jv_StackFrame *frame = &state.frames[i];
FillInFrameInfo (frame); FillInFrameInfo (frame);
if (seen_checkClass if (seen_checkClass)
&& frame->klass
&& frame->klass != checkClass)
{ {
jframe_count++; if (frame->klass)
if (start_pos == -1) {
start_pos = i; jframe_count++;
if (start_pos == -1)
start_pos = i;
}
} }
else
if (!seen_checkClass seen_checkClass = frame->klass == checkClass;
&& frame->klass
&& frame->klass == checkClass)
seen_checkClass = true;
} }
result = (JArray<jclass> *) _Jv_NewObjectArray (jframe_count, &Class::class$, NULL); result = (JArray<jclass> *) _Jv_NewObjectArray (jframe_count, &Class::class$, NULL);
int pos = 0; int pos = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment