public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* ISA checks for factories
@ 2007-10-03  8:36 Phil Muldoon
  2007-10-03 19:43 ` Andrew Cagney
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Muldoon @ 2007-10-03  8:36 UTC (permalink / raw)
  To: Frysk Hackers

I've written several factories to decide what class to instantiate 
depending on the ISA. These usually end up as hacks, probably because I 
do not understand something quite right, or there is no real decent  
"What ISA does this task/proc belong" discovery.

I can instance check an ISA with:

Isa isa = proc.getIsa();
if (isa instanceof IsaIA32) ....

and so on, but that will not work for 32 on 64 ISAs. For example, on a 
32 bit process on a 64 bit system, the instance returned would be

LinuxIa32On64

And those cannot be instance checked as they are package private, while 
the "native" ISAs are public.

So what is the solution here? Open the scope of the xxOnxx ISAs? I get 
the feeling that instanceof checks tell me that we need to work on a 
better solution anyway. Reverting to reflection screams hack to me.

Regards

Phil

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ISA checks for factories
  2007-10-03  8:36 ISA checks for factories Phil Muldoon
@ 2007-10-03 19:43 ` Andrew Cagney
  2007-10-09  7:53   ` Phil Muldoon
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Cagney @ 2007-10-03 19:43 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: Frysk Hackers

Phil,

unfortunate timing, we crossed e-mails during the night,

Phil Muldoon wrote:
> I've written several factories to decide what class to instantiate 
> depending on the ISA. These usually end up as hacks, probably because 
> I do not understand something quite right, or there is no real decent  
> "What ISA does this task/proc belong" discovery.
>
> I can instance check an ISA with:
>
> Isa isa = proc.getIsa();
There is now also:
    ISA isa = task.getISA()
which returns a frysk.isa.ISA, which looks smells and behaves like an 
ENUM.  This new ISA just the following attributes:
   - family (i386, x8664, PPC)
   - word size (4, 8)
   - byte order (little, big)
leading to the combinations: IA32, X8664, PPC32LE, PPC32BE, PPC64LE, 
PPC64BE.

> if (isa instanceof IsaIA32) ....

It can then be used as either:

    if (isa == ISA.IA32)
      ..
    else if (isa = ISA.X8664)
      ..

or better?:

   ISAMap map = new ISAMap("why am I here")
       .put(ISA.IA32, new My(IA32))
       .put(ISA.X8664, new My(X8664))
       ;
   ...
       // Throws a RuntimeException if ISA missing
       My o = (My) map.get(task.getISA);

which could easily be wrapped up in a factory.

Andrew


>
> and so on, but that will not work for 32 on 64 ISAs. For example, on a 
> 32 bit process on a 64 bit system, the instance returned would be
>
> LinuxIa32On64
>
> And those cannot be instance checked as they are package private, 
> while the "native" ISAs are public.
>
> So what is the solution here? Open the scope of the xxOnxx ISAs? I get 
> the feeling that instanceof checks tell me that we need to work on a 
> better solution anyway. Reverting to reflection screams hack to me.
>
> Regards
>
> Phil

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ISA checks for factories
  2007-10-03 19:43 ` Andrew Cagney
@ 2007-10-09  7:53   ` Phil Muldoon
  2007-10-09  9:16     ` Phil Muldoon
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Muldoon @ 2007-10-09  7:53 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Frysk Hackers

Andrew Cagney wrote:
> Phil,
>
> There is now also:
>    ISA isa = task.getISA()
> which returns a frysk.isa.ISA, which looks smells and behaves like an 
> ENUM.  This new ISA just the following attributes:
>   - family (i386, x8664, PPC)
>   - word size (4, 8)
>   - byte order (little, big)
> leading to the combinations: IA32, X8664, PPC32LE, PPC32BE, PPC64LE, 
> PPC64BE.
>

Ok that makes sense, I got that from the original email, but ...


> or better?:
>
>   ISAMap map = new ISAMap("why am I here")
>       .put(ISA.IA32, new My(IA32))
>       .put(ISA.X8664, new My(X8664))
>       ;
>   ...
>       // Throws a RuntimeException if ISA missing
>       My o = (My) map.get(task.getISA);
>
>
I'm still a little fuzzy on how it can be used to detected IA 32 on 64, 
or PPC32 On 64?

Regards

Phil


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ISA checks for factories
  2007-10-09  7:53   ` Phil Muldoon
@ 2007-10-09  9:16     ` Phil Muldoon
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Muldoon @ 2007-10-09  9:16 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Frysk Hackers

Phil Muldoon wrote:
> I'm still a little fuzzy on how it can be used to detected IA 32 on 
> 64, or PPC32 On 64?
>

Answering my own question. I looked at the code, and it appears that 
Task.getISA() will return the contextually correct ISA for the situation 
in hand. So for a 32bit process on x8664 it will return the 32 bit ISA 
and so on. Previously one had to instance check the ISA as a 32On64 ISA 
was returned explicitly.

I'll rewrite the LinuxCorefileFactory to use this new method now.

Regards

Phil


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-09  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-03  8:36 ISA checks for factories Phil Muldoon
2007-10-03 19:43 ` Andrew Cagney
2007-10-09  7:53   ` Phil Muldoon
2007-10-09  9:16     ` Phil Muldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).