This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [committed] allow assert in inner class

Actually, for inner classes, they should be checking the assertion level of the enclosing class. There is a whole series of tests for correct semantics in jacks. And does your patch work for asserts inside an inner class of an interface, since interfaces can't have a static helper?

Also, 1.5 compliant VMs support the ldc bytecode with a CONSTANT_Class argument, alleviating the need for emitting the class$ helper method (although you still need this code to allow targeting older VMs). The 1.5 VM also expands the range of legal .classfile descriptors to include non-Java-characters, so that the compiler now has a reserved namespace (hence, javac now emits Foo+1.class instead of Foo$1.class, among others). Other VM additions include lots of new attributes: EnclosingMethod, AnnotationDefault, RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations. There are also new access flags (such as ACC_ATTRIBUTE, 0x2000).

Per Bothner wrote:

If you use assert, the compiler generates some code
that includes doing THIS_CLASS.class, which in turn
is implemented by a static helper method named class$.
If THIS_CLASS was an inner class, the compiler would
lose because static methods aren't allowed in inner classes.
The solution (which matches JDK) is to move the class$
helper method to the outer class.

Tested on Fedora and checked into mainline.


2004-02-25 Per Bothner <>

	* parse.y (build_assertion):  If we're in an inner class, create the
	class$ helper routine in the outer class.

Index: parse.y
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.469
diff -u -p -r1.469 parse.y
--- parse.y 19 Feb 2004 22:39:55 -0000 1.469
+++ parse.y 26 Feb 2004 05:27:18 -0000
@@ -15301,6 +15301,10 @@ build_assertion (int location, tree cond
tree field, classdollar, id, call;
tree class_type = TREE_TYPE (klass);
+ tree outer_class = klass;
+ while (INNER_CLASS_DECL_P (outer_class))
+ outer_class = DECL_CONTEXT (outer_class);
+ outer_class = TREE_TYPE (outer_class);
field = add_field (class_type,
get_identifier ("$assertionsDisabled"),
@@ -15309,9 +15313,10 @@ build_assertion (int location, tree cond
FIELD_SYNTHETIC (field) = 1;
- if (!TYPE_DOT_CLASS (class_type))
- build_dot_class_method (class_type);
- classdollar = build_dot_class_method_invocation (class_type, class_type);
+ if (!TYPE_DOT_CLASS (outer_class))
+ build_dot_class_method (outer_class);
+ classdollar
+ = build_dot_class_method_invocation (outer_class, class_type);
/* Call CLASS.desiredAssertionStatus(). */
id = build_wfl_node (get_identifier ("desiredAssertionStatus"));

-- Someday, I might put a cute statement here.

Eric Blake

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]