This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Illegal Package-Private Accesses Yet Again!
- From: Ranjit Mathew <rmathew at hotmail dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: java-patches at gcc dot gnu dot org
- Date: Tue, 30 Mar 2004 19:05:28 +0530
- Subject: Re: Illegal Package-Private Accesses Yet Again!
- References: <406870ED.735183B6@hotmail.com> <406871C0.74A9025E@hotmail.com> <16488.29631.945497.590191@cuddles.cambridge.redhat.com>
Andrew Haley wrote:
> Ranjit Mathew writes:
> > Hi,
> >
> > Here's the promised follow up patch to my previous mail that
> > temporarily avoids illegal package-private accesses in libgcj.
> >
> > Please, please, *PLEASE* let us apply this (or something
> > similar)!
>
> Why not just make a few native access methods for the package private
> members.
Ok. Attached is my attempt at avoiding these problems
in a different manner.
First, I note that StackTraceElement and NameFinder are in
the same package and NameFinder.lookup() is called only
by java.lang.VMThrowable - so I modified lookup( ) to
directly take in a StackTraceElement.
(BTW, VMThrowable's header indicates that it is a part of
GNU Classpath, but I could not find it there. :-/)
Second, I created a passthrough native helper method
in natNameFinder.cc to call the package-private constructor
in java.lang.StackTraceElement.
Does this look better?
(It survived a clean-build of libgcj with my package-private
patch applied to GCJ and the testsuite showed no new failures.)
Ranjit.
Index: ChangeLog
from Ranjit Mathew <rmathew@hotmail.com>
* java/lang/VMThrowable.java (getStackTrace): Pass trace as is to
modified lookup().
* gnu/gcj/runtime/NameFinder.java (lookup): Change to take in a
StackTraceElement directly.
(newElement): New native helper method to create StackTraceElement
bypassing Java access control.
(createStackTraceElement): Use newElement() instead of directly
calling StackTraceElement's constructor.
* gnu/gcj/runtime/natNameFinder.cc (newElement): New method.
Index: java/lang/VMThrowable.java
===================================================================
--- java/lang/VMThrowable.java 2004-03-30 16:17:28.000000000 +0530
+++ java/lang/VMThrowable.java 2004-03-30 16:43:36.000000000 +0530
@@ -96,8 +96,7 @@ final class VMThrowable
if (trace != null)
{
NameFinder nameFinder = new NameFinder();
- result = nameFinder.lookup(t, trace.stackTraceAddrs(),
- trace.length());
+ result = nameFinder.lookup(t, trace);
nameFinder.close();
}
else
Index: gnu/gcj/runtime/NameFinder.java
===================================================================
--- gnu/gcj/runtime/NameFinder.java 2004-03-30 16:14:06.000000000 +0530
+++ gnu/gcj/runtime/NameFinder.java 2004-03-30 17:59:53.000000000 +0530
@@ -241,8 +241,11 @@ public class NameFinder
* Given an Throwable and a native stacktrace returns an array of
* StackTraceElement containing class, method, file and linenumbers.
*/
- public StackTraceElement[] lookup(Throwable t, RawData addrs, int length)
+ public StackTraceElement[] lookup(Throwable t, StackTrace trace)
{
+ RawData addrs = trace.stackTraceAddrs();
+ int length = trace.length();
+
StackTraceElement[] elements = new StackTraceElement[length];
for (int i=0; i < length; i++)
elements[i] = lookup(addrs, i);
@@ -353,6 +356,16 @@ public class NameFinder
}
/**
+ * Native helper method to create a StackTraceElement. Needed to work
+ * around normal Java access restrictions.
+ */
+ native private StackTraceElement newElement(String fileName,
+ int lineNumber,
+ String className,
+ String methName,
+ boolean isNative);
+
+ /**
* Creates a StackTraceElement given a string and a filename.
* Splits the given string into the class and method part.
* The string name will be a demangled to a fully qualified java method
@@ -363,7 +376,7 @@ public class NameFinder
private StackTraceElement createStackTraceElement(String name, String file)
{
if (!demangle)
- return new StackTraceElement(file, -1, null, name, false);
+ return newElement(file, -1, null, name, false);
String s = demangleName(name);
String methodName = s;
@@ -409,7 +422,7 @@ public class NameFinder
}
}
- return new StackTraceElement(fileName, line, className, methodName, false);
+ return newElement(fileName, line, className, methodName, false);
}
/**
Index: gnu/gcj/runtime/natNameFinder.cc
===================================================================
--- gnu/gcj/runtime/natNameFinder.cc 2004-03-30 17:09:43.000000000 +0530
+++ gnu/gcj/runtime/natNameFinder.cc 2004-03-30 18:00:23.000000000 +0530
@@ -48,6 +48,17 @@ details. */
#endif /* ! __USER_LABEL_PREFIX__ */
+java::lang::StackTraceElement*
+gnu::gcj::runtime::NameFinder::newElement (java::lang::String* fileName,
+ jint lineNumber,
+ java::lang::String* className,
+ java::lang::String* methName,
+ jboolean isNative)
+{
+ return new java::lang::StackTraceElement( fileName, lineNumber,
+ className, methName, isNative);
+}
+
java::lang::String*
gnu::gcj::runtime::NameFinder::getExternalLabel (java::lang::String* name)
{