This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Java patch: cleanup for primitive ".TYPE" class handling
- To: java-patches at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Subject: Java patch: cleanup for primitive ".TYPE" class handling
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- Date: Wed, 03 Oct 2001 23:34:45 +1200
GCJ currently specially handles primitive type expressions like
"Integer.TYPE", replacing them with references to "_Jv_integerClass" and
such. There isn't any need for this and we can get rid of a bunch of
code by removing it. In the runtime we can make initialization of
primitive type classes a little cleaner and more efficient by using
their type code rather than a string.
OK to commit the compiler part?
Bryce.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.117
diff -u -r1.117 expr.c
--- expr.c 2001/09/21 16:58:21 1.117
+++ expr.c 2001/10/03 10:09:58
@@ -2266,22 +2266,6 @@
return;
}
- /* Inline references to java.lang.PRIMTYPE.TYPE.
- In addition to being a useful (minor) optimization,
- this is also needed to avoid circularities in the implementation
- of these fields in libjava. */
- if (field_name == TYPE_identifier_node && ! is_putting
- && ! flag_emit_class_files && field_type == class_ptr_type
- && strncmp (self_name, "java.lang.", 10) == 0)
- {
- tree typ = build_primtype_type_ref (self_name);
- if (typ)
- {
- push_value (typ);
- return;
- }
- }
-
field_ref = build_field_ref (field_ref, self_type, field_name);
if (is_static)
field_ref = build_class_init (self_type, field_ref);
@@ -2311,38 +2295,6 @@
}
else
push_value (field_ref);
-}
-
-tree
-build_primtype_type_ref (self_name)
- const char *self_name;
-{
- const char *class_name = self_name+10;
- tree typ;
- if (strncmp(class_name, "Byte", 4) == 0)
- typ = byte_type_node;
- else if (strncmp(class_name, "Short", 5) == 0)
- typ = short_type_node;
- else if (strncmp(class_name, "Integer", 7) == 0)
- typ = int_type_node;
- else if (strncmp(class_name, "Long", 4) == 0)
- typ = long_type_node;
- else if (strncmp(class_name, "Float", 5) == 0)
- typ = float_type_node;
- else if (strncmp(class_name, "Double", 6) == 0)
- typ = double_type_node;
- else if (strncmp(class_name, "Boolean", 7) == 0)
- typ = boolean_type_node;
- else if (strncmp(class_name, "Char", 4) == 0)
- typ = char_type_node;
- else if (strncmp(class_name, "Void", 4) == 0)
- typ = void_type_node;
- else
- typ = NULL_TREE;
- if (typ != NULL_TREE)
- return build_class_ref (typ);
- else
- return NULL_TREE;
}
void
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.122
diff -u -r1.122 java-tree.h
--- java-tree.h 2001/09/14 22:58:37 1.122
+++ java-tree.h 2001/10/03 10:09:59
@@ -1102,7 +1102,6 @@
extern char *print_int_node PARAMS ((tree));
extern void parse_error_context PARAMS ((tree cl, const char *, ...))
ATTRIBUTE_PRINTF_2;
-extern tree build_primtype_type_ref PARAMS ((const char *));
extern void finish_class PARAMS ((void));
extern void java_layout_seen_class_methods PARAMS ((void));
extern unsigned int check_for_initialization PARAMS ((tree));
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.315
diff -u -r1.315 parse.y
--- parse.y 2001/09/27 19:20:12 1.315
+++ parse.y 2001/10/03 10:10:10
@@ -258,7 +258,6 @@
static int check_method_types_complete PARAMS ((tree));
static void java_check_regular_methods PARAMS ((tree));
static void java_check_abstract_methods PARAMS ((tree));
-static tree maybe_build_primttype_type_ref PARAMS ((tree, tree));
static void unreachable_stmt_error PARAMS ((tree));
static tree find_expr_with_wfl PARAMS ((tree));
static void missing_return_error PARAMS ((tree));
@@ -12243,8 +12242,6 @@
`+' operator. Build `parm.toString()' and expand it. */
if ((temp = patch_string (parm)))
parm = temp;
- /* Inline PRIMTYPE.TYPE read access */
- parm = maybe_build_primttype_type_ref (parm, wfl);
TREE_VALUE (cn) = parm;
}
@@ -12786,33 +12783,6 @@
return 1;
}
-/* Inline references to java.lang.PRIMTYPE.TYPE when accessed in
- read. This is needed to avoid circularities in the implementation
- of these fields in libjava. */
-
-static tree
-maybe_build_primttype_type_ref (rhs, wfl)
- tree rhs, wfl;
-{
- tree to_return = NULL_TREE;
- tree rhs_type = TREE_TYPE (rhs);
- if (TREE_CODE (rhs) == COMPOUND_EXPR)
- {
- tree n = TREE_OPERAND (rhs, 1);
- if (TREE_CODE (n) == VAR_DECL
- && DECL_NAME (n) == TYPE_identifier_node
- && rhs_type == class_ptr_type
- && TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION
- && TREE_CODE (EXPR_WFL_NODE (wfl)) == IDENTIFIER_NODE)
- {
- const char *self_name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl));
- if (!strncmp (self_name, "java.lang.", 10))
- to_return = build_primtype_type_ref (self_name);
- }
- }
- return (to_return ? to_return : rhs );
-}
-
/* 15.25 Assignment operators. */
static tree
@@ -12923,10 +12893,6 @@
error_found = 1;
}
- /* Inline read access to java.lang.PRIMTYPE.TYPE */
- if (new_rhs)
- new_rhs = maybe_build_primttype_type_ref (new_rhs, wfl_op2);
-
if (error_found)
return error_mark_node;
@@ -14866,10 +14832,7 @@
}
if (new_value)
- {
- new_value = maybe_build_primttype_type_ref (new_value, wfl_value);
- TREE_VALUE (entry) = new_value;
- }
+ TREE_VALUE (entry) = new_value;
if (array_type_string)
free (array_type_string);
2001-10-03 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* java/lang/VMClassLoader.java (getPrimitiveClass): Now native. Now
takes a jchar type-code argument, not a string.
* java/lang/natClassLoader.cc (VMClassLoader::getPrimitiveClass):
New method. Just call _Jv_FindClassFromSignature.
java/lang/Boolean.java (TYPE): Initialize from
VMClassLoader.getPrimitiveClass using type-code.
java/lang/Character.java (TYPE): Likewise.
java/lang/Double.java (TYPE): Likewise.
java/lang/Float.java (TYPE): Likewise.
java/lang/Integer.java (TYPE): Likewise.
java/lang/Long.java (TYPE): Likewise.
java/lang/Short.java (TYPE): Likewise.
java/lang/Void.java (TYPE): Likewise.
Index: java/lang/VMClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/VMClassLoader.java,v
retrieving revision 1.4
diff -u -r1.4 VMClassLoader.java
--- VMClassLoader.java 2001/07/24 14:31:42 1.4
+++ VMClassLoader.java 2001/10/03 11:01:41
@@ -54,32 +54,9 @@
/**
* Helper for java.lang.Integer, Byte, etc. to get the TYPE class
- * at initialization time. If there are multiple classloaders, this
- * method may be called once per ClassLoader per type.
+ * at initialization time.
*
- * @param type name of the primitive type; i.e. "int", "byte", etc.
- * @return a "bogus" class representing the primitive type.
+ * @param type code for the primitive type.
*/
- static final Class getPrimitiveClass(String type)
- {
- if ("int".equals (type))
- return int.class;
- else if ("long".equals (type))
- return long.class;
- else if ("boolean".equals (type))
- return boolean.class;
- else if ("short".equals (type))
- return short.class;
- else if ("char".equals (type))
- return char.class;
- else if ("byte".equals (type))
- return byte.class;
- else if ("float".equals (type))
- return float.class;
- else if ("double".equals (type))
- return double.class;
- else if ("void".equals (type))
- return void.class;
- return null;
- }
+ static native Class getPrimitiveClass(char type);
}
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.37
diff -u -r1.37 natClassLoader.cc
--- natClassLoader.cc 2001/09/21 16:59:12 1.37
+++ natClassLoader.cc 2001/10/03 11:01:41
@@ -34,6 +34,7 @@
#include <java/lang/ClassCircularityError.h>
#include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/VirtualMachineError.h>
+#include <java/lang/VMClassLoader.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/Runtime.h>
#include <java/lang/StringBuffer.h>
@@ -175,6 +176,14 @@
klass->notifyAll ();
}
+jclass
+java::lang::VMClassLoader::getPrimitiveClass (jchar type)
+{
+ char sig[2];
+ sig[0] = (char) type;
+ sig[1] = '\0';
+ return _Jv_FindClassFromSignature (sig, NULL);
+}
// This is the findClass() implementation for the System classloader. It is
// the only native method in VMClassLoader, so we define it here.
Index: java/lang/Boolean.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Boolean.java,v
retrieving revision 1.7
diff -u -r1.7 Boolean.java
--- Boolean.java 2001/07/23 20:01:28 1.7
+++ Boolean.java 2001/10/03 11:01:41
@@ -60,7 +60,7 @@
* The primitive type <code>boolean</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass("boolean");
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('Z');
/**
* The immutable value of this Boolean.
Index: java/lang/Byte.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Byte.java,v
retrieving revision 1.6
diff -u -r1.6 Byte.java
--- Byte.java 2001/07/23 20:01:28 1.6
+++ Byte.java 2001/10/03 11:01:41
@@ -57,7 +57,7 @@
* The primitive type <code>byte</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass("byte");
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('B');
/**
* The immutable value of this Byte.
Index: java/lang/Character.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Character.java,v
retrieving revision 1.6
diff -u -r1.6 Character.java
--- Character.java 2000/12/15 05:53:39 1.6
+++ Character.java 2001/10/03 11:01:42
@@ -33,9 +33,7 @@
public static final int MIN_RADIX = 2;
public static final int MAX_RADIX = 36;
- // This initialization is seemingly circular, but it is accepted
- // by javac, and is handled specially by gcc.
- public static final Class TYPE = char.class;
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('C');
// Space.
public static final byte SPACE_SEPARATOR = 12;
Index: java/lang/Double.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Double.java,v
retrieving revision 1.9
diff -u -r1.9 Double.java
--- Double.java 2001/02/09 22:13:33 1.9
+++ Double.java 2001/10/03 11:01:42
@@ -26,9 +26,7 @@
public static final double POSITIVE_INFINITY = 1.0d/0.0d;
public static final double NaN = 0.0d/0.0d;
- // This initialization is seemingly circular, but it is accepted
- // by javac, and is handled specially by gcc.
- public static final Class TYPE = double.class;
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('D');
private double value;
Index: java/lang/Float.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Float.java,v
retrieving revision 1.8
diff -u -r1.8 Float.java
--- Float.java 2001/02/09 22:13:33 1.8
+++ Float.java 2001/10/03 11:01:42
@@ -26,9 +26,7 @@
public static final float POSITIVE_INFINITY = 1.0f/0.0f;
public static final float NaN = 0.0f/0.0f;
- // This initialization is seemingly circular, but it is accepted
- // by javac, and is handled specially by gcc.
- public static final Class TYPE = float.class;
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('F');
private float value;
Index: java/lang/Integer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Integer.java,v
retrieving revision 1.10
diff -u -r1.10 Integer.java
--- Integer.java 2001/07/30 17:58:32 1.10
+++ Integer.java 2001/10/03 11:01:42
@@ -58,7 +58,7 @@
* The primitive type <code>int</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass ("int");
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass ('I');
/**
* The immutable value of this Integer.
Index: java/lang/Long.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Long.java,v
retrieving revision 1.9
diff -u -r1.9 Long.java
--- Long.java 2001/07/23 20:01:28 1.9
+++ Long.java 2001/10/03 11:01:42
@@ -60,7 +60,7 @@
* The primitive type <code>long</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass ("long");
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J');
/**
* The immutable value of this Long.
Index: java/lang/Short.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Short.java,v
retrieving revision 1.6
diff -u -r1.6 Short.java
--- Short.java 2001/07/23 20:01:28 1.6
+++ Short.java 2001/10/03 11:01:42
@@ -56,7 +56,7 @@
* The primitive type <code>short</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass("short");
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('S');
/**
* The immutable value of this Short.
Index: java/lang/Void.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Void.java,v
retrieving revision 1.4
diff -u -r1.4 Void.java
--- Void.java 2001/10/01 18:24:54 1.4
+++ Void.java 2001/10/03 11:01:42
@@ -47,7 +47,7 @@
* The return type <code>void</code> is represented by this
* <code>Class</code> object.
*/
- public static final Class TYPE = VMClassLoader.getPrimitiveClass("void");
+ public static final Class TYPE = VMClassLoader.getPrimitiveClass('V');
/**
* Don't allow Void objects to be made.