Private no-args constructor

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Private no-args constructor

rvjansen
Hi Mike,

A question: in java, when there is no no-args default constructor defined, the compiler gives you one for free - that one is public.

In NetRexx scripting-mode, when one does not define a class in the program source, you get the class definition for free from the NetRexx translator, and when there is no no-args default constructor one also gets a generated one.

That one, however, is private. At least its attribute bits tell me that.

Well, two questions:

1) do you remember why that is?
2) do you mind if I change that?

This because I now implemented a NetRexxC.clgMain method that compiles and loads and executes a class, all in memory and no files, not even a .class file. It only works when I add the public ctor and that precludes scripting mode for now.

P.S. With this, we can run pipes identical to their VM counterparts now.

René.
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Private no-args constructor

Mike Cowlishaw
1) Looonng time ago .. suspect the idea was to not generate public methods
that user might not expect .. but allow the class itself (and subclasses?)
to use it.

2) feel free :-).

Mike
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: 05 August 2019 18:37
> To: [hidden email]
> Subject: [Ibm-netrexx] Private no-args constructor
>
> Hi Mike,
>
> A question: in java, when there is no no-args default
> constructor defined, the compiler gives you one for free -
> that one is public.
>
> In NetRexx scripting-mode, when one does not define a class
> in the program source, you get the class definition for free
> from the NetRexx translator, and when there is no no-args
> default constructor one also gets a generated one.
>
> That one, however, is private. At least its attribute bits
> tell me that.
>
> Well, two questions:
>
> 1) do you remember why that is?
> 2) do you mind if I change that?
>
> This because I now implemented a NetRexxC.clgMain method that
> compiles and loads and executes a class, all in memory and no
> files, not even a .class file. It only works when I add the
> public ctor and that precludes scripting mode for now.
>
> P.S. With this, we can run pipes identical to their VM
> counterparts now.
>
> René.
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : https://urldefense.proofpoint.com/v2/url?u=http-3A__ibm-2Dnetrexx.215625.n3.nabble.com_&d=DwIFAw&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=LLYGZ3UCOfn_q0D0MVE9TOBHQoBtMCuaK2oBBGy_gIY&s=rMP2fdcAoezvbn2Yo1DNxwavbIixitr5hqkgjQmNr3g&e= 
>
>


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Private no-args constructor

Mike Cowlishaw
In reply to this post by rvjansen
PS:

> A question: in java, when there is no no-args default
> constructor defined, the compiler gives you one for free -
> that one is public.

Thinking about it .. I suspect I followed what Java did.  Maybe it has
changed ...

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Private no-args constructor

rvjansen
In reply to this post by Mike Cowlishaw
I found that the RxClass source has a comment that explains that in a class with only static methods, the generated constructor becomes private, to avoid someone instantiating it. 
This brought me to understand that I had one reflective call too many. So I did not need to change constructor generation after all.

nrxsrc  = "say 'hello dynamic world’"
clsName = 'helloDyn'
org.netrexx.process.NetRexxC.clgMain(clsName,nrxsrc)

The new method in NetRexxC does:

 method clgMain(arg=Rexx, programstring=String) constant
    classList = ArrayList()
    rc = main(arg' -nologo -verbose0',[String programstring],null,classList)
    mapLoader = RxMapClassLoader classList.get(0)
    do
      c = mapLoader.findClass(arg)
      /* o = Object c.newInstance() <— that was the culprit */
      paramTypes = Class[1]
      paramTypes[0] = String[].class
      methodName = String "main"
      m = c.getMethod(methodName, paramTypes)
      params = Object[1]
      params[0] = String[0]
      m.invoke(null, params)
    catch e=Exception
      say 'Reflection exception encountered:'
      say e.getMessage()
    end

    return rc

This has the advantage that for longer running classes full hotspot optimization will work. Startup time now is about half a second on the fastest systems, with the largest performance gains on systems with slow I/O - everything works from memory, there is no file generated containing NetRexx or Java source, even the compiled class runs from its bytearray memory image. So while the interpreter has slightly faster startup, it loses in the long run. Most of this was prepared already by Kermit, but he never got around to take it to the final step. Now, for the pipes implementation, it means one can run a pipeline exactly like on z/VM - compile, load and go are all hidden from the user, no need to specify a class name or start a class in a java vm. (Btw, the interpreter fails on all generated pipeline netrexx source, that is the next thing to look into - might still use that on slower systems).

Thanks for the inspiration that led to the solution of this problem!

best regards,

René.






On 5 Aug 2019, at 20:15, Mike Cowlishaw <[hidden email]> wrote:

1) Looonng time ago .. suspect the idea was to not generate public methods
that user might not expect .. but allow the class itself (and subclasses?)
to use it.

2) feel free :-).

Mike


-----Original Message-----
From: [hidden email] 
[[hidden email]] On Behalf Of 
[hidden email]
Sent: 05 August 2019 18:37
To: [hidden email]
Subject: [Ibm-netrexx] Private no-args constructor

Hi Mike,

A question: in java, when there is no no-args default 
constructor defined, the compiler gives you one for free - 
that one is public.

In NetRexx scripting-mode, when one does not define a class 
in the program source, you get the class definition for free 
from the NetRexx translator, and when there is no no-args 
default constructor one also gets a generated one.

That one, however, is private. At least its attribute bits 
tell me that.

Well, two questions:

1) do you remember why that is?
2) do you mind if I change that?

This because I now implemented a NetRexxC.clgMain method that 
compiles and loads and executes a class, all in memory and no 
files, not even a .class file. It only works when I add the 
public ctor and that precludes scripting mode for now.

P.S. With this, we can run pipes identical to their VM 
counterparts now. 

René.
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : https://urldefense.proofpoint.com/v2/url?u=http-3A__ibm-2Dnetrexx.215625.n3.nabble.com_&d=DwIFAw&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=LLYGZ3UCOfn_q0D0MVE9TOBHQoBtMCuaK2oBBGy_gIY&s=rMP2fdcAoezvbn2Yo1DNxwavbIixitr5hqkgjQmNr3g&e= 




_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Private no-args constructor

Mike Cowlishaw
Glad my ancient commentary was useful!
 
Sounds good ...
 
Mike


From: [hidden email] [mailto:[hidden email]] On Behalf Of René Jansen
Sent: 05 August 2019 23:02
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] Private no-args constructor

I found that the RxClass source has a comment that explains that in a class with only static methods, the generated constructor becomes private, to avoid someone instantiating it. 
This brought me to understand that I had one reflective call too many. So I did not need to change constructor generation after all.

nrxsrc  = "say 'hello dynamic world’"
clsName = 'helloDyn'
org.netrexx.process.NetRexxC.clgMain(clsName,nrxsrc)

The new method in NetRexxC does:

 method clgMain(arg=Rexx, programstring=String) constant
    classList = ArrayList()
    rc = main(arg' -nologo -verbose0',[String programstring],null,classList)
    mapLoader = RxMapClassLoader classList.get(0)
    do
      c = mapLoader.findClass(arg)
      /* o = Object c.newInstance() <— that was the culprit */
      paramTypes = Class[1]
      paramTypes[0] = String[].class
      methodName = String "main"
      m = c.getMethod(methodName, paramTypes)
      params = Object[1]
      params[0] = String[0]
      m.invoke(null, params)
    catch e=Exception
      say 'Reflection exception encountered:'
      say e.getMessage()
    end

    return rc

This has the advantage that for longer running classes full hotspot optimization will work. Startup time now is about half a second on the fastest systems, with the largest performance gains on systems with slow I/O - everything works from memory, there is no file generated containing NetRexx or Java source, even the compiled class runs from its bytearray memory image. So while the interpreter has slightly faster startup, it loses in the long run. Most of this was prepared already by Kermit, but he never got around to take it to the final step. Now, for the pipes implementation, it means one can run a pipeline exactly like on z/VM - compile, load and go are all hidden from the user, no need to specify a class name or start a class in a java vm. (Btw, the interpreter fails on all generated pipeline netrexx source, that is the next thing to look into - might still use that on slower systems).

Thanks for the inspiration that led to the solution of this problem!

best regards,

René.






On 5 Aug 2019, at 20:15, Mike Cowlishaw <[hidden email]> wrote:

1) Looonng time ago .. suspect the idea was to not generate public methods
that user might not expect .. but allow the class itself (and subclasses?)
to use it.

2) feel free :-).

Mike


-----Original Message-----
From: [hidden email] 
[[hidden email]] On Behalf Of 
[hidden email]
Sent: 05 August 2019 18:37
To: [hidden email]
Subject: [Ibm-netrexx] Private no-args constructor

Hi Mike,

A question: in java, when there is no no-args default 
constructor defined, the compiler gives you one for free - 
that one is public.

In NetRexx scripting-mode, when one does not define a class 
in the program source, you get the class definition for free 
from the NetRexx translator, and when there is no no-args 
default constructor one also gets a generated one.

That one, however, is private. At least its attribute bits 
tell me that.

Well, two questions:

1) do you remember why that is?
2) do you mind if I change that?

This because I now implemented a NetRexxC.clgMain method that 
compiles and loads and executes a class, all in memory and no 
files, not even a .class file. It only works when I add the 
public ctor and that precludes scripting mode for now.

P.S. With this, we can run pipes identical to their VM 
counterparts now. 

René.
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : https://urldefense.proofpoint.com/v2/url?u=http-3A__ibm-2Dnetrexx.215625.n3.nabble.com_&d=DwIFAw&c=jf_iaSHvJObTbx-siA1ZOg&r=_6rXNpPJ1fYV-3bV1za02NiR4PUelvicfHXwtnTXpXE&m=LLYGZ3UCOfn_q0D0MVE9TOBHQoBtMCuaK2oBBGy_gIY&s=rMP2fdcAoezvbn2Yo1DNxwavbIixitr5hqkgjQmNr3g&e= 




_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/