This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: LocalVariableTypeTable support
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 20 Jan 2005 10:55:52 -0700
- Subject: [gcjx] Patch: FYI: LocalVariableTypeTable support
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
With this patch we now generate a LocalVariableTypeTable attribute for
those methods that need it (when -g is enabled).
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* bytecode/generate.cc (generate): Add LocalVariableTypeTable if
requested.
* bytecode/locals.cc (emit): Added 'types' argument. Changed
return type.
(any_parameterized_p): New method.
* bytecode/locals.hh (locals::emit): Updated.
(locals::size): Removed.
(locals::any_parameterized_p): Declare.
* bytecode/generate.hh (local_variable_table_attribute::use_types):
New field.
(local_variable_table_attribute::bytes): New field.
(local_variable_table_attribute): Updated. Added new argument.
(local_variable_table_attribute::emit): Updated.
(local_variable_table_attribute::size): Rewrote.
Index: bytecode/generate.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/generate.cc,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 generate.cc
--- bytecode/generate.cc 16 Jan 2005 04:36:41 -0000 1.1.2.5
+++ bytecode/generate.cc 20 Jan 2005 17:58:22 -0000
@@ -178,8 +178,14 @@
attributes.push_back (new line_table_attribute (cpool, this));
if (vars.update ())
- attributes.push_back (new local_variable_table_attribute (cpool,
- &vars));
+ {
+ attributes.push_back (new local_variable_table_attribute (cpool,
+ &vars,
+ false));
+ if (global->get_compiler ()->target_15 ()
+ && vars.any_parameterized_p ())
+ attributes.push_back (new local_variable_table_attribute (cpool, &vars, true));
+ }
}
}
Index: bytecode/generate.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/generate.hh,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 generate.hh
--- bytecode/generate.hh 16 Jan 2005 04:36:41 -0000 1.1.2.4
+++ bytecode/generate.hh 20 Jan 2005 17:58:22 -0000
@@ -191,25 +191,35 @@
{
locals *vars;
+ // True if we're emitting the type table, not the ordinary table.
+ bool use_types;
+
+ // Number of bytes we're going to emit.
+ int bytes;
+
public:
- local_variable_table_attribute (output_constant_pool *p, locals *v)
- : bytecode_attribute (p, "LocalVariableTable"),
- vars (v)
+ local_variable_table_attribute (output_constant_pool *p, locals *v,
+ bool types)
+ : bytecode_attribute (p, (types ? "LocalVariableTypeTable"
+ : "LocalVariableTable")),
+ vars (v),
+ use_types (types)
{
- // This is inefficient, we could cache information.
- vars->emit (pool, NULL);
+ bytes = vars->emit (pool, NULL, use_types);
+ // We shouldn't make an empty table.
+ assert (bytes > 0);
}
void emit (bytecode_stream &writer)
{
bytecode_attribute::emit (writer);
- vars->emit (pool, &writer);
+ vars->emit (pool, &writer, use_types);
}
int size ()
{
- return vars->size ();
+ return bytes;
}
};
Index: bytecode/locals.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/locals.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 locals.cc
--- bytecode/locals.cc 16 Jan 2005 04:36:41 -0000 1.1.2.3
+++ bytecode/locals.cc 20 Jan 2005 17:58:22 -0000
@@ -159,8 +159,29 @@
return valid > 0;
}
-void
-locals::emit (output_constant_pool *pool, bytecode_stream *out)
+bool
+locals::any_parameterized_p ()
+{
+ for (std::list<debug_info>::iterator i = var_descriptions.begin ();
+ i != var_descriptions.end ();
+ ++i)
+ {
+ debug_info &info (*i);
+ if (! info.start->live_p () || info.start == info.end)
+ continue;
+
+ model_type *t = info.variable->type ();
+ if (t->erasure () == t)
+ continue;
+
+ return true;
+ }
+ return false;
+}
+
+int
+locals::emit (output_constant_pool *pool, bytecode_stream *out,
+ bool types)
{
int count = 0;
for (std::list<debug_info>::iterator i = var_descriptions.begin ();
@@ -171,12 +192,16 @@
if (! info.start->live_p () || info.start == info.end)
continue;
+ model_type *t = info.variable->type ();
+ if (types && t->erasure () == t)
+ continue;
+
++count;
if (! out)
{
// Make sure these are in the pool.
pool->add_utf (info.variable->get_name ());
- pool->add_utf (info.variable->type ()->get_descriptor ());
+ pool->add_utf (types ? t->get_signature () : t->get_descriptor ());
}
}
@@ -184,7 +209,7 @@
assert (count > 0);
if (! out)
- return;
+ return 2 + 10 * count;
out->put2 (count);
for (std::list<debug_info>::const_iterator i = var_descriptions.begin ();
@@ -195,10 +220,19 @@
if (! info.start->live_p () || info.start == info.end)
continue;
+ model_type *t = info.variable->type ();
+ if (types && t->erasure () == t)
+ continue;
+
out->put2 (info.start->get_pc ());
out->put2 (info.end->get_pc () - info.start->get_pc ());
out->put2 (pool->add_utf (info.variable->get_name ()));
- out->put2 (pool->add_utf (info.variable->type ()->get_descriptor ()));
+ out->put2 (pool->add_utf (types ? t->get_signature ()
+ : t->get_descriptor ()));
out->put2 (info.index);
}
+
+ // The return value here doesn't matter, but we might as well be
+ // correct.
+ return 2 + 10 * count;
}
Index: bytecode/locals.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/locals.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 locals.hh
--- bytecode/locals.hh 16 Jan 2005 04:36:41 -0000 1.1.2.3
+++ bytecode/locals.hh 20 Jan 2005 17:58:22 -0000
@@ -117,14 +117,15 @@
/// Used when generating debug information. Write the actual
/// information. If the writer is NULL, just enter information into
- /// the constant pool.
- void emit (output_constant_pool *, bytecode_stream *);
-
- /// Return the size of the local variable table attribute.
- int size ()
- {
- return 2 + 10 * valid;
- }
+ /// the constant pool and return the number of bytes that will be
+ /// emitted. The final argument is true if we are emitting a
+ /// LocalVariableTypeTable, false if we are emitting a
+ /// LocalVariableTable.
+ int emit (output_constant_pool *, bytecode_stream *, bool);
+
+ /// Return true if any local variable has a parameterized type (and
+ /// thus a LocalVariableTypeTable is required).
+ bool any_parameterized_p ();
};
/// This is an class for allocating a temporary local variable. Usage