[x3d-public] X3DJSAIL: Exceeding Java String limits on setValue? What do wedo?

Don Brutzman brutzman at nps.edu
Thu Mar 30 00:32:49 PDT 2017


John: tonight's X3DJSAIL update has further append() methods for the field types.

Attached is an example using this approach that compiles successfully.

On 3/29/2017 7:52 PM, yottzumm at gmail.com wrote:
> The arrays as floats also cause “code too large” issues.

Basically yes, and splitting them up into separate method calls didn't help.  8(

Though I think that they do compile better than strings, and floats take half as much space as doubles, so fewer converted scenes encounter the problem.

Also tried changing ANT_OPTS to a bigger memory model.  No effect.

Finally resorted to a search for "java error: code too large" (when all else fails, read the manual) and immediately found the answer on StackOverflow.

The limiting factor is compiled methods in the JVM are not allowed to be greater than 64KB.  Wow.

	http://stackoverflow.com/questions/2407912/code-too-large-compilation-error-in-java

	http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3

So... what's happening is that the wondrously long functional programming style (single semicolon for an entire method!) is running up against an internal Java design constraint.  Ouch.

Knowing this, finally, the fix should be straightforward.  For big mesh values like long coordinate arrays and index arrays, we simply need to make them class member variables in the source code, rather than hardwired into a method.

Presumably this programming constraint in Java exists for good performance-optimization reasons.

So... presumably the next path forward for scene conversion will be to look for L A R G E arrays and define those data structures first, then continue to define the method that produces the X3DObject scene graph and have it refer back to that large object.

Another step forward...  and no wasted time really, we are fixing other issues as we go.  The added methods are helpful.

Here are replies to your other points too.

>  The strings were a special case, because it was a value field (I guess I didn’t have the type?).

All of the type handling is "under the hood" for fieldObject and fieldValueObject.  Based on the type definition provided by the author, values are converted to numbers/booleans internally as appropriate even if the author uses string-based get/set accessor methods.

>    The best I have so far is adding 840 (the next step is 2520) element arrays one at a time to an MF object with append, but you can perhaps figure something else out (variable parameters).  I need MF append methods which return objects and not voids, though, and an append can’t take a single SF value.  That’s no good, because it will produce methods which are the same size or bigger than the original.

I think you will find the added methods handle these cases.  If something is missing, or incorrectly returning void, please let me know and I'll fix them.

> See previous example for set and append methods and divide-and-conquer (should we take a logarithmic approach or heuristic?).

I was able to replace of all the heuristic type matching in X3dToJava.xslt so that is all strict and correct now.


> *From: *Don Brutzman <mailto:brutzman at nps.edu>
> *Sent: *Wednesday, March 29, 2017 1:17 PM
> *To: *yottzumm at gmail.com <mailto:yottzumm at gmail.com>
> *Cc: *X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Subject: *Re: X3DJSAIL: Exceeding Java String limits on setValue? What do wedo?
>
>
> Third, now that arrays can be effectively handled as floats rather than strings, this opens the door to re-tackling any remaining "code too large" compilation issues - there are a few examples of that, especially for meshes.  Will next work on how to subdivide exceedingly long arrays (perhaps 100 tuples at a time) and see if the set and append methods support such a divide-and-conquer approach.  Any good techniques you've found will be good to share, TIA.


all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
-------------- next part --------------
package X3dForAdvancedModeling.Animation;

/*
Copyright (c) 1995-2017 held by the author(s).  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer
      in the documentation and/or other materials provided with the
      distribution.
    * Neither the name of the Web3D Consortium (http://www.web3D.org)
      nor the names of its contributors may be used to endorse or
      promote products derived from this software without specific
      prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.EventUtilities.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Interpolation.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Texturing.*;
import org.web3d.x3d.jsail.Time.*;

/*
   <meta name="generator" content="X3dToJava.xslt stylesheet to create X3DJSAIL Java program from X3D source." />
   <meta name="url"       content="http://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" />
   <meta name="reference" content="X3DJSAIL, http://www.web3d.org/specifications/java/X3DJSAIL.html" />
*/
 
public class BoxSwitch
{
  X3DObject x3dModelObjectTree = new X3DObject().setProfile("Immersive").setVersion("3.3")
  .setHead(new headObject()
    .setMeta(new metaObject().setName("title").setContent("BoxSwitch.x3d"))
    .setMeta(new metaObject().setName("creator").setContent("Don Brutzman"))
    .setMeta(new metaObject().setName("created").setContent("30 December 2015"))
    .setMeta(new metaObject().setName("modified").setContent("4 March 2017"))
    .setMeta(new metaObject().setName("description").setContent("Show animation by switching Box nodes that are each covered by a different ImageTexture."))
    .setMeta(new metaObject().setName("reference").setContent("../GeometricShapes/CubeWithLabeledSides.x3d"))
    .setMeta(new metaObject().setName("drawing").setContent("../GeometricShapes/images/CubeSideImages.vsd"))
    .setMeta(new metaObject().setName("identifier").setContent("http://x3dGraphics.com/examples/X3dForAdvancedModeling/Animation/BoxSwitch.x3d"))
    .setMeta(new metaObject().setName("generator").setContent("X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"))
    .setMeta(new metaObject().setName("license").setContent("../license.html")))
  .setScene(new SceneObject()
    .addChild(new BackgroundObject().setSkyColor(new MFColorObject(new float[] {0.8f,0.8f,0.9f})))
    .addChild(new NavigationInfoObject())
    .addChild(new SwitchObject("BoxSwitcher").setWhichChoice(-1)
      .addChild(new ShapeObject()
        .setGeometry(new BoxObject("UnitBox"))
        .setAppearance(new AppearanceObject()
          .setTexture(new ImageTextureObject().setUrl(new MFStringObject("\"../GeometricShapes/images/RedImage.png\" \"http://x3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/images/RedImage.png\"")))))
      .addChild(new ShapeObject()
        .setGeometry(new BoxObject().setUSE("UnitBox"))
        .setAppearance(new AppearanceObject()
          .setTexture(new ImageTextureObject().setUrl(new MFStringObject("\"../GeometricShapes/images/GreenImage.png\" \"http://x3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/images/GreenImage.png\"")))))
      .addChild(new ShapeObject()
        .setGeometry(new BoxObject().setUSE("UnitBox"))
        .setAppearance(new AppearanceObject()
          .setTexture(new ImageTextureObject().setUrl(new MFStringObject("\"../GeometricShapes/images/TurquoiseImage.png\" \"http://x3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/images/TurquoiseImage.png\"")))))
      .addChild(new ShapeObject()
        .setGeometry(new BoxObject().setUSE("UnitBox"))
        .setAppearance(new AppearanceObject()
          .setTexture(new ImageTextureObject().setUrl(new MFStringObject("\"../GeometricShapes/images/YellowImage.png\" \"http://x3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/images/YellowImage.png\"")))))
      .addChild(new ShapeObject()
        .setGeometry(new BoxObject().setUSE("UnitBox"))
        .setAppearance(new AppearanceObject()
          .setTexture(new ImageTextureObject().setUrl(new MFStringObject("\"../GeometricShapes/images/WhiteImage.png\" \"http://x3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/images/WhiteImage.png\"")))))
      .addChild(new ShapeObject()
        .setGeometry(new BoxObject().setUSE("UnitBox"))
        .setAppearance(new AppearanceObject()
          .setTexture(new ImageTextureObject().setUrl(new MFStringObject("\"../GeometricShapes/images/GreyImage.png\" \"http://x3dGraphics.com/examples/X3dForAdvancedModeling/GeometricShapes/images/GreyImage.png\""))))))
    .addComments("Animated Box")
    .addChild(new TimeSensorObject("Clock").setCycleInterval(12).setLoop(true))
    .addChild(new IntegerSequencerObject("Sequencer").setKey(new float[] {0.0f,0.1667f,0.3333f,0.5f,0.6667f,0.8333f,1.0f}).setKeyValue(new int[] {0,1,2,3,4,5,0}))
    .addChild(new ROUTEObject().setFromField("fraction_changed").setFromNode("Clock").setToField("set_fraction").setToNode("Sequencer"))
    .addChild(new ROUTEObject().setFromField("value_changed").setFromNode("Sequencer").setToField("whichChoice").setToNode("BoxSwitcher"))
    .addChild(new ViewpointObject("OrbitingView").setPosition(-8.0f,0.0f,0.0f).setOrientation(0.0f,1.0f,0.0f,-1.57f).setDescription("Orbiting view"))
    .addComments("Animated Viewpoint, orbiting about the origin")
    .addChild(new PositionInterpolatorObject("CircularPathPositionInterpolator").setKeyValue(new MFVec3fObject(new float[] {0.0f,0.0f,8.0f,1.389f,0.0f,7.878f,2.736f,0.0f,7.518f,4.0f,0.0f,6.928f,5.142f,0.0f,6.128f,6.128f,0.0f,5.142f,6.928f,0.0f,4.0f,7.518f,0.0f,2.736f,7.878f,0.0f,1.389f,8.0f,0.0f,0.0f,7.878f,0.0f,-1.389f,7.518f,0.0f,-2.736f,6.928f,0.0f,-4.0f,6.128f,0.0f,-5.142f,5.142f,0.0f,-6.128f,4.0f,0.0f,-6.928f,2.736f,0.0f,-7.518f,1.389f,0.0f,-7.878f,0.0f,0.0f,-8.0f,-1.389f,0.0f,-7.878f,-2.736f,0.0f,-7.518f,-4.0f,0.0f,-6.928f,-5.142f,0.0f,-6.128f,-6.128f,0.0f,-5.142f,-6.928f,0.0f,-4.0f,-7.518f,0.0f,-2.736f,-7.878f,0.0f,-1.389f,-8.0f,0.0f,-0.0f,-7.878f,0.0f,1.389f,-7.518f,0.0f,2.736f,-6.928f,0.0f,4.0f,-6.128f,0.0f,5.142f,-5.142f,0.0f,6.128f,-4.0f,0.0f,6.928f,-2.736f,0.0f,7.518f,-1.389f,0.0f,7.878f,0.0f,0.0f,8.0f})).setKey(new float[] {0.0f,0.02778f,0.05556f,0.08333f,0.11111f,0.13889f,0.16667f,0.19444f,0.22222f,0.25f,0.27778f,0.30556f,0.33333f,0.36111f,0.38889f,0.41667f,0.44444f,0.47222f,0.5f,0.52778f,0.55556f,0.58333f,0.61111f,0.63889f,0.66667f,0.69444f,0.72222f,0.75f,0.77778f,0.80556f,0.83333f,0.86111f,0.88889f,0.91667f,0.94444f,0.97222f,1.0f}))
    .addChild(new ROUTEObject().setFromField("fraction_changed").setFromNode("Clock").setToField("set_fraction").setToNode("CircularPathPositionInterpolator"))
    .addChild(new ROUTEObject().setFromField("value_changed").setFromNode("CircularPathPositionInterpolator").setToField("position").setToNode("OrbitingView"))
    .addChild(new OrientationInterpolatorObject("CenterFacingOrientationInterpolator").setKey(new float[] {0.0f,0.3333f,0.6667f,1.0f}).setKeyValue(new MFRotationObject(new float[] {0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,2.094395f,0.0f,1.0f,0.0f,4.18879f,0.0f,1.0f,0.0f,0.0f})))
    .addChild(new ROUTEObject().setFromField("fraction_changed").setFromNode("Clock").setToField("set_fraction").setToNode("CenterFacingOrientationInterpolator"))
    .addChild(new ROUTEObject().setFromField("value_changed").setFromNode("CenterFacingOrientationInterpolator").setToField("orientation").setToNode("OrbitingView"))
    .addComments("Additional Viewpoints")
    .addChild(new ViewpointObject().setOrientation(0.0f,1.0f,0.0f,1.57f).setPosition(8.0f,0.0f,0.0f).setDescription("Front view"))
    .addChild(new ViewpointObject().setPosition(-8.0f,0.0f,0.0f).setOrientation(0.0f,1.0f,0.0f,-1.57f).setDescription("Back view"))
    .addChild(new ViewpointObject().setPosition(0.0f,0.0f,8.0f).setDescription("Left view"))
    .addChild(new ViewpointObject().setPosition(0.0f,0.0f,-8.0f).setOrientation(0.0f,1.0f,0.0f,3.1416f).setDescription("Right view"))
    .addChild(new ViewpointObject().setPosition(0.0f,8.0f,0.0f).setOrientation(1.0f,0.0f,0.0f,-1.57f).setDescription("Top view"))
    .addChild(new ViewpointObject().setPosition(0.0f,-8.0f,0.0f).setOrientation(1.0f,0.0f,0.0f,1.57f).setDescription("Bottom view")));
}


More information about the x3d-public mailing list