Re: Class name in unused code aren't removed ?
He, Thanks for testing it. I did some more tests and noticed the following: --- In the above example, the method FactoryLogger.getLogger(BLA) returns null. If this method returns some Logger object on which I set handler (just a setter that I call on the newly created object), neither the field, or variable isn't removed (I am not using getClass ().getName() in this test). This is strange as the field/variable is never used in the code so it should always be removed, no mather what his value is. I noticed that when I return a new Logger instance and don't set the handler (comment the if statement below) it will be removed however. So the Factory method looks like this: public static method getLogger(String name) { Logger logger = new Logger(name); if (handler != null) { logger.setHandler(handler); } } -- My inner Enumeration class called DebugId isn't removed when it's not used. I use a Enum DebugId class to assign debugId's to the widgets (the UIObject.ensureDebugId() functionality). When I indicate in the gwt xml that the debug id's shouldn't be set, it will remove the usage of the DebugId enum as expected, but does leave this Enum class in the final javascript while it's not referenced anymore. Shouldn't it remove this Enum class ? I will change it to constants string value's... I suppose it should be removed then. BTW: the above was all tested against 1.5.2. -- Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Class name in unused code aren't removed ?
Hi all, I was having a closer look and noticed (I am using gwt 1.5.2 still) that a variable and field that isn't used, isn't removed by the compiler if it has the class name as value. I did a little test with the following code. The example class LabelWidgetFactoryCms contains the following fields and method: private final Logger F_TEST1 = FactoryLogger.getLogger(this.getClass ().getName() + TEST1); private final Logger F_TEST2 = FactoryLogger.getLogger(TEST2); private final String F_TEST3 = TEST3; private final Logger F_TEST4 = new Logger(this.getClass().getName() + TEST4); private final Logger F_TEST5 = new Logger(TEST5); private final String F_TEST6 = this.getClass().getName() + TEST6; private final String F_TEST7 = LabelWidgetFactoryCms.class.getName() + TEST; public Widget createTextWidget(final String key) { Logger L_TEST1 = FactoryLogger.getLogger(this.getClass().getName() + TEST1); Logger L_TEST2 = FactoryLogger.getLogger(TEST2); String L_TEST3 = TEST3; Logger L_TEST4 = new Logger(this.getClass().getName() + TEST4); Logger L_TEST5 = new Logger(TEST5); String F_TEST6 = this.getClass().getName() + TEST6; String F_TEST7 = LabelWidgetFactoryCms.class.getName() + TEST7; return createLabelWidget(findContentItem(key)); } Note: - FactoryLogger.getLogger(String) simple returns null. - Neither the fields or the variables aren't used. The result of compiler with mode PRETTY is the following: function $LabelWidgetFactoryCms_0(this$static, formatter, toolTipProvider){ getLogger(this$static.getClass$().typeName + 'TEST1'); this$static.getClass$().typeName + 'TEST4'; this$static.getClass$().typeName + 'TEST6'; return this$static; } ... function $createTextWidget(this$static, key){ getLogger(this$static.getClass$().typeName + 'TEST1'); this$static.getClass$().typeName + 'TEST4'; this$static.getClass$().typeName + 'TEST6'; return this$static.createLabelWidget($findContentItem_0(this$static, key)); } ... Conclusion: - An unused field isn't removed when it includes the this class name. - An unused variable isn't removed when it included the this class name. H interesting especially the difference getClass().getName() and LabelWidgetFactoryCms.class.getName() Is this a bug or expected behavior? -- Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Class name in unused code aren't removed ?
I'm not sure if it's a missed optimization, but it seems the compiler cannot optimize away getClass() for some reason. If you do LabelWidgetFactoryCms.class, then it'll optimize it away properly. I just checked this behaviour is present in trunk as well: public void onModuleLoad() { String nothing = this.getClass().getName() + TEST; } In the compiled output, we see function init(){ !!$stats $stats({moduleName:$moduleName, subSystem:'startup', evtGroup:'moduleStartup', millis:(new Date()).getTime(), type:'onModuleLoadStart', className:'org.gwt.client.Sample'}); ($Sample(new Sample()) , Lorg_gwt_client_Sample_2_classLit).typeName + 'TEST'; } but only if I have private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class); declared as a field. This problem also appears with OBF. The problem appears to be that the compiler misses the optimization On Sun, Apr 19, 2009 at 4:02 PM, Ed post2edb...@hotmail.com wrote: Hi all, I was having a closer look and noticed (I am using gwt 1.5.2 still) that a variable and field that isn't used, isn't removed by the compiler if it has the class name as value. I did a little test with the following code. The example class LabelWidgetFactoryCms contains the following fields and method: private final Logger F_TEST1 = FactoryLogger.getLogger(this.getClass ().getName() + TEST1); private final Logger F_TEST2 = FactoryLogger.getLogger(TEST2); private final String F_TEST3 = TEST3; private final Logger F_TEST4 = new Logger(this.getClass().getName() + TEST4); private final Logger F_TEST5 = new Logger(TEST5); private final String F_TEST6 = this.getClass().getName() + TEST6; private final String F_TEST7 = LabelWidgetFactoryCms.class.getName() + TEST; public Widget createTextWidget(final String key) { Logger L_TEST1 = FactoryLogger.getLogger(this.getClass().getName() + TEST1); Logger L_TEST2 = FactoryLogger.getLogger(TEST2); String L_TEST3 = TEST3; Logger L_TEST4 = new Logger(this.getClass().getName() + TEST4); Logger L_TEST5 = new Logger(TEST5); String F_TEST6 = this.getClass().getName() + TEST6; String F_TEST7 = LabelWidgetFactoryCms.class.getName() + TEST7; return createLabelWidget(findContentItem(key)); } Note: - FactoryLogger.getLogger(String) simple returns null. - Neither the fields or the variables aren't used. The result of compiler with mode PRETTY is the following: function $LabelWidgetFactoryCms_0(this$static, formatter, toolTipProvider){ getLogger(this$static.getClass$().typeName + 'TEST1'); this$static.getClass$().typeName + 'TEST4'; this$static.getClass$().typeName + 'TEST6'; return this$static; } ... function $createTextWidget(this$static, key){ getLogger(this$static.getClass$().typeName + 'TEST1'); this$static.getClass$().typeName + 'TEST4'; this$static.getClass$().typeName + 'TEST6'; return this$static.createLabelWidget($findContentItem_0(this$static, key)); } ... Conclusion: - An unused field isn't removed when it includes the this class name. - An unused variable isn't removed when it included the this class name. H interesting especially the difference getClass().getName() and LabelWidgetFactoryCms.class.getName() Is this a bug or expected behavior? -- Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---