Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BED96200C6F for ; Tue, 9 May 2017 08:35:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BD5FF160BB6; Tue, 9 May 2017 06:35:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DC5A5160BB3 for ; Tue, 9 May 2017 08:35:23 +0200 (CEST) Received: (qmail 97455 invoked by uid 500); 9 May 2017 06:35:23 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 97445 invoked by uid 99); 9 May 2017 06:35:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 May 2017 06:35:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 8BFF8C047C for ; Tue, 9 May 2017 06:35:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.397 X-Spam-Level: X-Spam-Status: No, score=-1.397 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-2.796, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id ZXUb83HPQ74U for ; Tue, 9 May 2017 06:35:20 +0000 (UTC) Received: from mail-oi0-f44.google.com (mail-oi0-f44.google.com [209.85.218.44]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 7C5835F1B3 for ; Tue, 9 May 2017 06:35:19 +0000 (UTC) Received: by mail-oi0-f44.google.com with SMTP id w10so76345153oif.0 for ; Mon, 08 May 2017 23:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CcPFEBoRZWuDHeY0OwSG6jy6iGSwbt+APVyhRMY6tuA=; b=F26Xk6cmq38aZTYHERqdccuN65JGJA9y/uPPHT5dlinUBvrmS86kID0HrDDoAKyIF6 gvAAMXiHAk8RNHDD0L0ohhg0pYW91sHJ2GyyBNpQ5ZUI2HHeNQwMC7CFRGosquO8TGmg svs07rjsHS2kGrh1D5qgnyThWrFnqtDHvBnt5myGGvcfL9JAkXXNHdQC4Gb7wPdmHgBi vturVs3Ax8IE2wefPA29Y7nSLIWilDZVp81M5G5fup0ce/SfHCx6u8zPfVn0eclQqSUD cACKfTmHcmhjpHn3KjpTuNslUygyf4lyuWgHQ7V2H93g5GDmt5DZgLZnYZ/ajfLSAmVe XwKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CcPFEBoRZWuDHeY0OwSG6jy6iGSwbt+APVyhRMY6tuA=; b=Lh88p5FmLv5tO6rDcdkvHa8T5c8gAMqB6yx3D+0n3Or9WbIVL1iIhd0+WysicPptR0 WnWcFyOfekB0kSWcRpkymxIfl/jL5mmnUId+mMqj8VP3bE5hd+vqW3nRn1InhCBdd5Qy GG7oKjamChKDXc+u8UdhIwKzn9E/KL2fg1EXijVWi0FFFLrV7BOZcNkm5EKDq1uBAp+R kuYXmQFG5LCuiP2LFxWlHYvfzcwulAouaKQvH7q4w65fGPpgkrpMuitmy0/ASp4O6FQZ mOsqPUe1TCl0aOqdPWI1jmxIHTnyzkH/vNc9kGr9DvaNTASbrbeXpJE9Jx8N4nLwfYAC NaPA== X-Gm-Message-State: AN3rC/7/RpUwd8ARluAvqg0r2E0q6+R8NumcITnAN1ZLCnNHMyNsAnEW nTCHKt2XkTBKhx3bIZt//3szWEM/cuoj X-Received: by 10.202.49.139 with SMTP id x133mr11613614oix.131.1494311717879; Mon, 08 May 2017 23:35:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.133.6 with HTTP; Mon, 8 May 2017 23:34:57 -0700 (PDT) In-Reply-To: References: <5C676E6359909E478C7B811BDB48CA356C498D@CWWAPP478.windstream.com> From: Graeme Rocher Date: Tue, 9 May 2017 08:34:57 +0200 Message-ID: Subject: Re: Groovy AOT compilation To: users@groovy.apache.org Cc: Paul King Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable archived-at: Tue, 09 May 2017 06:35:24 -0000 Would it make sense to have the metaClass field of GroovyObject initialise lazily? In what circumstance would that be a breaking change? Concurrency? On Tue, May 9, 2017 at 8:25 AM, C=C3=A9dric Champeau wrote: > The reason is that even with static compilation, constructors include > metaclass initialization. This is something that have been bothering me f= or > a long time, and I wish we could rework that, but it's a behavioral break= ing > change (however, really unlikely to break things in real world). > > 2017-05-09 8:16 GMT+02:00 Sergei Egorov : >> >> Dear Paolo, >> >> Could you please share an example project? I would like to play with it = :) >> >> >> Best Regards, >> Sergei >> >> On Tue, May 9, 2017 at 1:04 AM Paolo Di Tommaso >> wrote: >>> >>> That would make sense. However apart of that there's still a lot of >>> reflection behind the scene even when using StaticCompile. For example = just >>> replacing the println statement with a `new Hello()` in the previous >>> snippet, I'm getting the following errors when trying to compile with t= he >>> AOT compiler: >>> >>> >>> >>> groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createWithCustomL= ookup(Class, >>> MetaClassRegistry): Method is marked as deleted: >>> HotSpotMethod >>> at >>> groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createWithCustomL= ookup(MetaClassRegistry.java:149) >>> at >>> groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create(MetaClassR= egistry.java:144) >>> at >>> org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInf= o.java:259) >>> at >>> org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:30= 2) >>> at Hello.$getStaticMetaClass(Hello.groovy) >>> at Hello.(Hello.groovy) >>> at Hello.main(Hello.groovy:5) >>> at com.oracle.svm.core.JavaMainWrapper.run(stripped:111) >>> >>> org.codehaus.groovy.reflection.CachedClass$8.initValue(): Method is >>> marked as deleted: HotSpotMethod >>> at >>> org.codehaus.groovy.reflection.CachedClass$8.initValue(CachedClass.java= :216) >>> at >>> org.codehaus.groovy.reflection.CachedClass$8.initValue(CachedClass.java= :214) >>> at >>> org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49) >>> at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:40) >>> at >>> org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:= 274) >>> at >>> org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.initialize(Closu= reMetaClass.java:474) >>> at >>> org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInf= o.java:260) >>> at >>> org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:30= 2) >>> at Hello.$getStaticMetaClass(Hello.groovy) >>> at Hello.(Hello.groovy) >>> at Hello.main(Hello.groovy:5) >>> at com.oracle.svm.core.JavaMainWrapper.run(stripped:111) >>> >>> >>> Here the offending methods are Class.getConstructor(Class[]) and >>> Class.getInterfaces(). >>> >>> Does the MetaClassRegistry mechanism is really needed when using the >>> Groovy static compilation ? >>> >>> >>> p >>> >>> On Tue, May 9, 2017 at 12:29 AM, Paul King wrote: >>>> >>>> That line was added to break a hard-dependency on the groovy-xml modul= e >>>> by the core groovy module. With Java 9's "real" modules, we'd potentia= lly >>>> want to rework that. I haven't really thought about what we might do i= nstead >>>> but welcome to suggestions/ideas/PRs. >>>> >>>> Cheers, Paul. >>>> >>>> >>>> On Tue, May 9, 2017 at 6:35 AM, Paolo Di Tommaso >>>> wrote: >>>>> >>>>> Good question. I leave the answer to Groovy core developers, however = as >>>>> far as I've understood even when the code is statically compiled, Gro= ovy >>>>> still uses reflection in runtime helper methods. For example one of t= he >>>>> first issue I've encountered it's raised by the following line in the >>>>> InvokeHelper.format method that the AOT compiler is unable to transla= te to >>>>> native code >>>>> >>>>> Method serialize =3D >>>>> Class.forName("groovy.xml.XmlUtil").getMethod("serialize", Element.cl= ass); >>>>> >>>>> >>>>> >>>>> p >>>>> >>>>> On Mon, May 8, 2017 at 5:35 PM, Winnebeck, Jason >>>>> wrote: >>>>>> >>>>>> I think a biggest question than AOT compatibility is why does compil= e >>>>>> static still need to do reflection? I thought that was the point was= to >>>>>> disable it, especially for Android support=E2=80=A6? Unless the issu= e is the >>>>>> metaclass generation, does compile static still generate metaclasses= ? >>>>>> >>>>>> >>>>>> >>>>>> Jason >>>>>> >>>>>> >>>>>> >>>>>> From: Paolo Di Tommaso [mailto:paolo.ditommaso@gmail.com] >>>>>> Sent: Monday, May 08, 2017 11:02 AM >>>>>> To: users@groovy.apache.org >>>>>> Subject: Groovy AOT compilation >>>>>> >>>>>> >>>>>> >>>>>> Dear all, >>>>>> >>>>>> >>>>>> >>>>>> I just want to share with you my experience with the Java AOT compil= er >>>>>> a came across a few days ago. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Although they said clearly that it still an experimental project and >>>>>> it does not support dynamic class loading and most of reflection, I = turns >>>>>> out it's possible to compile a basic static Groovy class, eg: >>>>>> >>>>>> >>>>>> >>>>>> @groovy.transform.CompileStatic >>>>>> >>>>>> class Hello { >>>>>> >>>>>> >>>>>> >>>>>> static void main( String... args ) { >>>>>> >>>>>> System.out.println "Hello world!" >>>>>> >>>>>> } >>>>>> >>>>>> } >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> This mean that it creates a native 5MB binary executable, that can r= un >>>>>> on any machine without the need of the Java VM nor the Groovy runtim= e! in 12 >>>>>> millisecond! cool!! >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Unfortunately the good news stops here. I was unable to successfully >>>>>> compile any other piece of code, which for example uses a Groovy "pr= intln" >>>>>> method or just instantiate a class. The problem seems to be that, ev= en >>>>>> though the code is statically compiled, Groovy uses reflection behin= d the >>>>>> scene to instantiate classes and performs other operations. >>>>>> >>>>>> >>>>>> >>>>>> Now, I guess this is certainly not a Groovy top priority, however >>>>>> since there is an on-going discussion around a major Groovy reengine= ering to >>>>>> make it compatible with the upcoming Java 9 module system, I was won= dering >>>>>> if it would not make sense to include the support for the Java AOT c= ompiler >>>>>> as a goal for a future Groovy 3/4 release? >>>>>> >>>>>> >>>>>> >>>>>> Personally I think it would be an extremely useful feature and a maj= or >>>>>> achievement for the project. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> What do you think ? >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Cheers, >>>>>> >>>>>> Paolo >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> This email message and any attachments are for the sole use of the >>>>>> intended recipient(s). Any unauthorized review, use, disclosure or >>>>>> distribution is prohibited. If you are not the intended recipient, p= lease >>>>>> contact the sender by reply email and destroy all copies of the orig= inal >>>>>> message and any attachments. >>>>> >>>>> >>>> >>> > --=20 Graeme Rocher