This is the mail archive of the java@gcc.gnu.org mailing list for the Java 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: values types for Java [message reformatted]


Jeff Sturm wrote:

> > Such types should be marked with some additional attributes in the
> > classfile.
>
> Perhaps.  For gcj's purposes it may be sufficient to generate compatible
> bytecode, and leverage struct optimizations when compiling from source.
>
> A simple example:
>
> struct S {
>   int a,b;
> }
>
> class C {
>   int x,y;
>   S s;
> }
>
> might produce bytecode equivalent to:
>
> class C {
>   int x,y,s$a,s$b;
> }
>
> I can imagine something similar for method parameters.  Struct return
> values are a little trickier; they could be wrapped in some other object
> perhaps.
>

Maybe you could pass each struct field as out parameters (in practice as
reference parameter) automagically added by the compiler. Thus:

    S M(T x) { .... return s;...}

would be compiled as

    void M(T x, int* s$a, int* s$b) { ... s$a = s.a; s$b = s.b; return;....}

(I'm not sure whether this is possible in gcj, but I would try a solution
along these lines)

>
> > Anyway, this restriction would be formulated in the language report as
> > "value types are final subclasses of Object". This restriction is often
> > mentioned and could make sense (Per proposed it). This would
automatically
> > remove the need for virtual dispatch.
>
> But even Object has a vtable.  I feel making value types a subclass of
> Object undermines the value of this proposal, having simple, lightweight
> stack-allocated structs.
>
> You could disallow these types from having Object semantics, but that
> seems awkward to me.

This is why (in both proposals) structs cannot be casted to Object.

-Patrik


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