This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
module constant values
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Thu, 15 Dec 2011 19:14:05 -0500
- Subject: module constant values
Hello,
While looking at some compiler output the other day, I noticed that
if a module defines a constant like
(define-constant FOO ::int 42)
that the compiled class file contains
Field name: FOO public static final Signature: int
Attribute "ConstantValue", length:2, value: Integer 42
but then it also has in <clinit>
10: bipush 42
12: putstatic <Field some_module.FOO int>
which seems unnecessary to me. If I put
public static final int FOO = 42;
in a Java source file, the compiled bytecode will have a field with
ConstantValue attribute and that's all.
I discovered that I can suppress the putstatic by adding something like
for (Attribute attr = decl.field.getAttributes(); attr != null;
attr = attr.getNext())
{
if (attr instanceof ConstantValueAttr)
return;
}
near the top of BindingInitializer#emit(), but it's not clear to me
whether that's the right place to make a change. Perhaps the
BindingInitializer shouldn't be created in the first place if the
Declaration's field has had a ConstantValue set. But this happens in
SetExp#compile(), which has
if (decl.shouldEarlyInit())
BindingInitializer.create(decl, new_value, comp);
and Declaration#shouldEarlyInit() seems written specifically so that
for constants it will return true.
Am I missing something? What's the rationale for initializing the
value of a field that already has its value hard-coded?
Thanks,
Jamie
--
Jamison Hope
The PTR Group
www.theptrgroup.com