changeset 10459:6efa37ea0d1c

8178804: Excessive memory consumption in TriangleMesh/MeshView Reviewed-by: kcr
author ckyang
date Fri, 21 Apr 2017 16:47:39 -0700
parents 78c32a6084ab
children a8026ed85c2b 70738e6d9554
files modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGTriangleMesh.java modules/javafx.graphics/src/main/java/com/sun/prism/impl/BaseMesh.java modules/javafx.graphics/src/shims/java/com/sun/javafx/sg/prism/NGTriangleMeshShim.java modules/javafx.graphics/src/shims/java/com/sun/prism/impl/BaseMeshShim.java modules/javafx.graphics/src/shims/java/javafx/scene/shape/TriangleMeshShim.java tests/system/src/test/addExports tests/system/src/test/java/test/com/sun/prism/impl/PNTMeshVertexBufferLengthTest.java tests/system/src/test/java/test/com/sun/prism/impl/Vec3f.java
diffstat 8 files changed, 709 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGTriangleMesh.java	Fri Apr 21 13:42:23 2017 -0700
+++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGTriangleMesh.java	Fri Apr 21 16:47:39 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -178,4 +178,8 @@
     float[] test_getTexCoords() {
         return this.texCoords;
     }
+    // NOTE: This method is used for unit test purpose only.
+    Mesh test_getMesh() {
+        return this.mesh;
+    }
 }
--- a/modules/javafx.graphics/src/main/java/com/sun/prism/impl/BaseMesh.java	Fri Apr 21 13:42:23 2017 -0700
+++ b/modules/javafx.graphics/src/main/java/com/sun/prism/impl/BaseMesh.java	Fri Apr 21 16:47:39 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -197,18 +197,20 @@
                 mf2vb = vbCount / VERTEX_SIZE_VB;
 
                 if (vertexBuffer.length <= vbCount) {
-                    final int incrementedSize = vbCount + 20; // Let's increment by 20
-                    float[] temp = new float[incrementedSize * VERTEX_SIZE_VB];
+                    int numVertices = vbCount / VERTEX_SIZE_VB;
+                    // Increment by 1/8th of numVertices or 6 (by 2 triangles) which ever is greater
+                    final int newNumVertices = numVertices + Math.max((numVertices >> 3), 6);
+                    float[] temp = new float[newNumVertices * VERTEX_SIZE_VB];
                     System.arraycopy(vertexBuffer, 0, temp, 0, vertexBuffer.length);
                     vertexBuffer = temp;
                     // Enlarge cachedNormals, cachedTangents and cachedBitangents too
-                    temp = new float[incrementedSize * 3];
+                    temp = new float[newNumVertices * 3];
                     System.arraycopy(cachedNormals, 0, temp, 0, cachedNormals.length);
                     cachedNormals = temp;
-                    temp = new float[incrementedSize * 3];
+                    temp = new float[newNumVertices * 3];
                     System.arraycopy(cachedTangents, 0, temp, 0, cachedTangents.length);
                     cachedTangents = temp;
-                    temp = new float[incrementedSize * 3];
+                    temp = new float[newNumVertices * 3];
                     System.arraycopy(cachedBitangents, 0, temp, 0, cachedBitangents.length);
                     cachedBitangents = temp;
                 }
@@ -815,6 +817,21 @@
         return face;
     }
 
+    // Package scope method for testing
+    boolean test_isVertexBufferNull() {
+        return vertexBuffer == null;
+    }
+
+    // Package scope method for testing
+    int test_getVertexBufferLength() {
+        return vertexBuffer.length;
+    }
+
+    // Package scope method for testing
+    int test_getNumberOfVertices() {
+        return numberOfVertices;
+    }
+
     class MeshGeomComp2VB {
 
         private final int key; // point or texCoord index
--- a/modules/javafx.graphics/src/shims/java/com/sun/javafx/sg/prism/NGTriangleMeshShim.java	Fri Apr 21 13:42:23 2017 -0700
+++ b/modules/javafx.graphics/src/shims/java/com/sun/javafx/sg/prism/NGTriangleMeshShim.java	Fri Apr 21 16:47:39 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
 
 package com.sun.javafx.sg.prism;
 
+import com.sun.prism.impl.BaseMesh;
+
 public class NGTriangleMeshShim extends NGTriangleMesh {
 
     @Override
@@ -52,4 +54,8 @@
         return super.test_getTexCoords();
     }
 
+    public static BaseMesh test_getMesh(NGTriangleMesh triMesh) {
+        return (BaseMesh) triMesh.test_getMesh();
+    }
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.graphics/src/shims/java/com/sun/prism/impl/BaseMeshShim.java	Fri Apr 21 16:47:39 2017 -0700
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.prism.impl;
+
+public class BaseMeshShim {
+    public static boolean test_isVertexBufferNull(BaseMesh mesh) {
+        return mesh.test_isVertexBufferNull();
+    }
+
+    public static int test_getVertexBufferLength(BaseMesh mesh) {
+        return mesh.test_getVertexBufferLength();
+    }
+
+    public static int test_getNumberOfVertices(BaseMesh mesh) {
+        return mesh.test_getNumberOfVertices();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.graphics/src/shims/java/javafx/scene/shape/TriangleMeshShim.java	Fri Apr 21 16:47:39 2017 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javafx.scene.shape;
+
+import com.sun.javafx.sg.prism.NGTriangleMesh;
+
+public class TriangleMeshShim {
+
+    public static NGTriangleMesh getNGMesh(Mesh mesh) {
+        return (NGTriangleMesh) mesh.getPGMesh();
+    }
+
+}
--- a/tests/system/src/test/addExports	Fri Apr 21 13:42:23 2017 -0700
+++ b/tests/system/src/test/addExports	Fri Apr 21 16:47:39 2017 -0700
@@ -19,7 +19,9 @@
 --add-exports javafx.graphics/com.sun.javafx.iio.png=ALL-UNNAMED
 --add-exports javafx.graphics/com.sun.javafx.image.impl=ALL-UNNAMED
 --add-exports javafx.graphics/com.sun.javafx.image=ALL-UNNAMED
+--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
 --add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
+--add-exports javafx.graphics/com.sun.prism.impl=ALL-UNNAMED
 # compilation additions
 --add-exports=javafx.graphics/com.sun.glass.events=ALL-UNNAMED
 --add-exports=java.desktop/sun.awt=ALL-UNNAMED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/system/src/test/java/test/com/sun/prism/impl/PNTMeshVertexBufferLengthTest.java	Fri Apr 21 16:47:39 2017 -0700
@@ -0,0 +1,379 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.com.sun.prism.impl;
+
+import com.sun.javafx.sg.prism.NGTriangleMesh;
+import com.sun.javafx.sg.prism.NGTriangleMeshShim;
+import com.sun.prism.impl.BaseMesh;
+import com.sun.prism.impl.BaseMeshShim;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.scene.Group;
+import javafx.scene.PerspectiveCamera;
+import javafx.scene.Scene;
+import javafx.scene.shape.MeshView;
+import javafx.scene.shape.TriangleMesh;
+import javafx.scene.shape.TriangleMeshShim;
+import javafx.scene.shape.VertexFormat;
+import javafx.scene.transform.Rotate;
+import javafx.stage.Stage;
+
+import junit.framework.AssertionFailedError;
+import org.junit.AfterClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import test.util.Util;
+
+import static test.util.Util.TIMEOUT;
+
+/**
+ * @test @bug 8178804
+ * @summary Excessive memory consumption in TriangleMesh/MeshView
+ */
+public class PNTMeshVertexBufferLengthTest {
+
+    // Sleep time showing/hiding window in milliseconds
+    private static final int SLEEP_TIME = 1000;
+
+    // Size of a vertex
+    private static final int VERTEX_SIZE = 9;
+
+    private static final float meshScale = 15;
+    private static final float minX = -10;
+    private static final float minY = -10;
+    private static final float maxX = 10;
+    private static final float maxY = 10;
+    private static final float funcValue = -10.0f;
+
+    private static final Vec3f v1 = new Vec3f();
+    private static final Vec3f v2 = new Vec3f();
+
+    private static void computeNormal(Vec3f pa, Vec3f pb, Vec3f pc, Vec3f normal) {
+        // compute Normal |(v1-v0)X(v2-v0)|
+        v1.sub(pb, pa);
+        v2.sub(pc, pa);
+        normal.cross(v1, v2);
+        normal.normalize();
+    }
+
+    private static double getSinDivX(double x, double y) {
+        double r = Math.sqrt(x * x + y * y);
+        return funcValue * (r == 0 ? 1 : Math.sin(r) / r);
+    }
+
+    private static void buildTriangleMesh(MeshView meshView,
+            int subDivX, int subDivY, float scale) {
+
+        final int pointSize = 3;
+        final int normalSize = 3;
+        final int texCoordSize = 2;
+        final int faceSize = 9; // 3 point indices, 3 normal indices and 3 texCoord indices per triangle
+        int numDivX = subDivX + 1;
+        int numVerts = (subDivY + 1) * numDivX;
+        float points[] = new float[numVerts * pointSize];
+        float texCoords[] = new float[numVerts * texCoordSize];
+        int faceCount = subDivX * subDivY * 2;
+        float normals[] = new float[faceCount * normalSize];
+        int faces[] = new int[faceCount * faceSize];
+
+        // Create points and texCoords
+        for (int y = 0; y <= subDivY; y++) {
+            float dy = (float) y / subDivY;
+            double fy = (1 - dy) * minY + dy * maxY;
+            for (int x = 0; x <= subDivX; x++) {
+                float dx = (float) x / subDivX;
+                double fx = (1 - dx) * minX + dx * maxX;
+                int index = y * numDivX * pointSize + (x * pointSize);
+                points[index] = (float) fx * scale;
+                points[index + 1] = (float) fy * scale;
+                points[index + 2] = (float) getSinDivX(fx, fy) * scale;
+                index = y * numDivX * texCoordSize + (x * texCoordSize);
+                texCoords[index] = dx;
+                texCoords[index + 1] = dy;
+            }
+        }
+
+        // Initial faces and normals
+        int normalCount = 0;
+        Vec3f[] triPoints = new Vec3f[3];
+        triPoints[0] = new Vec3f();
+        triPoints[1] = new Vec3f();
+        triPoints[2] = new Vec3f();
+        Vec3f normal = new Vec3f();
+        for (int y = 0; y < subDivY; y++) {
+            for (int x = 0; x < subDivX; x++) {
+                int p00 = y * numDivX + x;
+                int p01 = p00 + 1;
+                int p10 = p00 + numDivX;
+                int p11 = p10 + 1;
+                int tc00 = y * numDivX + x;
+                int tc01 = tc00 + 1;
+                int tc10 = tc00 + numDivX;
+                int tc11 = tc10 + 1;
+
+                int ii = p00 * 3;
+                triPoints[0].x = points[ii];
+                triPoints[0].y = points[ii + 1];
+                triPoints[0].z = points[ii + 2];
+                ii = p10 * 3;
+                triPoints[1].x = points[ii];
+                triPoints[1].y = points[ii + 1];
+                triPoints[1].z = points[ii + 2];
+                ii = p11 * 3;
+                triPoints[2].x = points[ii];
+                triPoints[2].y = points[ii + 1];
+                triPoints[2].z = points[ii + 2];
+                computeNormal(triPoints[0], triPoints[1], triPoints[2], normal);
+
+                int normalIndex = normalCount * normalSize;
+                normals[normalIndex] = normal.x; //nx
+                normals[normalIndex + 1] = normal.y; //ny
+                normals[normalIndex + 2] = normal.z; //nz
+
+                int index = (y * subDivX * faceSize + (x * faceSize)) * 2;
+                faces[index + 0] = p00;
+                faces[index + 1] = normalCount;
+                faces[index + 2] = tc00;
+                faces[index + 3] = p10;
+                faces[index + 4] = normalCount;
+                faces[index + 5] = tc10;
+                faces[index + 6] = p11;
+                faces[index + 7] = normalCount++;
+                faces[index + 8] = tc11;
+                index += faceSize;
+
+                ii = p11 * 3;
+                triPoints[0].x = points[ii];
+                triPoints[0].y = points[ii + 1];
+                triPoints[0].z = points[ii + 2];
+                ii = p01 * 3;
+                triPoints[1].x = points[ii];
+                triPoints[1].y = points[ii + 1];
+                triPoints[1].z = points[ii + 2];
+                ii = p00 * 3;
+                triPoints[2].x = points[ii];
+                triPoints[2].y = points[ii + 1];
+                triPoints[2].z = points[ii + 2];
+                computeNormal(triPoints[0], triPoints[1], triPoints[2], normal);
+                normalIndex = normalCount * normalSize;
+                normals[normalIndex] = normal.x; //nx
+                normals[normalIndex + 1] = normal.y; //ny
+                normals[normalIndex + 2] = normal.z; //nz
+
+                faces[index + 0] = p11;
+                faces[index + 1] = normalCount;
+                faces[index + 2] = tc11;
+                faces[index + 3] = p01;
+                faces[index + 4] = normalCount;
+                faces[index + 5] = tc01;
+                faces[index + 6] = p00;
+                faces[index + 7] = normalCount++;
+                faces[index + 8] = tc00;
+            }
+        }
+
+
+        TriangleMesh triangleMesh = new TriangleMesh(VertexFormat.POINT_NORMAL_TEXCOORD);
+        triangleMesh.getPoints().setAll(points);
+        triangleMesh.getNormals().setAll(normals);
+        triangleMesh.getTexCoords().setAll(texCoords);
+        triangleMesh.getFaces().setAll(faces);
+        meshView.setMesh(triangleMesh);
+    }
+
+    // Used to launch the application before running any test
+    private static final CountDownLatch launchLatch = new CountDownLatch(1);
+
+    // Singleton Application instance
+    static MyApp myApp;
+
+    private CountDownLatch latch = new CountDownLatch(1);
+
+    // Application class. An instance is created and initialized before running
+    // the first test, and it lives through the execution of all tests.
+    public static class MyApp extends Application {
+
+        Stage primaryStage = null;
+        MeshView meshView;
+
+        @Override
+        public void init() {
+            PNTMeshVertexBufferLengthTest.myApp = this;
+        }
+
+        @Override
+        public void start(Stage primaryStage) throws Exception {
+            primaryStage.setTitle("PNTMeshVertexBufferLengthTest");
+            TriangleMesh triangleMesh = new TriangleMesh(VertexFormat.POINT_NORMAL_TEXCOORD);
+            meshView = new MeshView(triangleMesh);
+            Group rotateGrp = new Group(meshView);
+            rotateGrp.setRotate(-30);
+            rotateGrp.setRotationAxis(Rotate.X_AXIS);
+            Group translateGrp = new Group(rotateGrp);
+            translateGrp.setTranslateX(200);
+            translateGrp.setTranslateY(200);
+            translateGrp.setTranslateZ(100);
+            Group root = new Group(translateGrp);
+
+            Scene scene = new Scene(root);
+            primaryStage.setScene(scene);
+            primaryStage.setX(0);
+            primaryStage.setY(0);
+            primaryStage.setWidth(400);
+            primaryStage.setHeight(400);
+            PerspectiveCamera perspectiveCamera = new PerspectiveCamera();
+            scene.setCamera(perspectiveCamera);
+            primaryStage.show();
+            this.primaryStage = primaryStage;
+            launchLatch.countDown();
+        }
+    }
+
+    @BeforeClass
+    public static void setupOnce() {
+        // Start the Application
+        new Thread(() -> Application.launch(MyApp.class, (String[]) null)).start();
+
+        try {
+            if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
+                throw new AssertionFailedError("Timeout waiting for Application to launch");
+            }
+        } catch (InterruptedException ex) {
+            AssertionFailedError err = new AssertionFailedError("Unexpected exception");
+            err.initCause(ex);
+            throw err;
+        }
+
+        assertEquals(0, launchLatch.getCount());
+    }
+
+    @AfterClass
+    public static void teardownOnce() {
+        Platform.exit();
+    }
+
+    // ========================== TEST CASES ==========================
+    @Test(timeout = 5000)
+    public void testMeshWithZeroDiv() throws InterruptedException {
+        Util.runAndWait(() -> {
+            Scene scene = myApp.primaryStage.getScene();
+            buildTriangleMesh(myApp.meshView, 0, 0, meshScale);
+        });
+        Thread.sleep(SLEEP_TIME);
+
+        NGTriangleMesh ngTriMesh = TriangleMeshShim.getNGMesh(myApp.meshView.getMesh());
+        assertNotNull(ngTriMesh);
+        BaseMesh baseMesh = NGTriangleMeshShim.test_getMesh(ngTriMesh);
+        assertNotNull(baseMesh);
+        // empty mesh (0 vertices)
+        assertEquals(0, BaseMeshShim.test_getNumberOfVertices(baseMesh));
+        assertTrue(BaseMeshShim.test_isVertexBufferNull(baseMesh));
+    }
+
+    @Test(timeout = 5000)
+    public void testMeshWithOneDiv() throws InterruptedException {
+        Util.runAndWait(() -> {
+            Scene scene = myApp.primaryStage.getScene();
+            buildTriangleMesh(myApp.meshView, 1, 1, meshScale);
+        });
+        Thread.sleep(SLEEP_TIME);
+
+        NGTriangleMesh ngTriMesh = TriangleMeshShim.getNGMesh(myApp.meshView.getMesh());
+        assertNotNull(ngTriMesh);
+        BaseMesh baseMesh = NGTriangleMeshShim.test_getMesh(ngTriMesh);
+        assertNotNull(baseMesh);
+        // mesh with 6 vertices (2 triangles)
+        assertEquals(6, BaseMeshShim.test_getNumberOfVertices(baseMesh));
+        // vertexBuffer started with 4 vertices and grew by 6 (since 12.5% or 1/8th
+        // of 4 is  less than 6). Size of vertex is 9 floats (10 * VERTEX_SIZE = 90)
+        assertEquals(10 * VERTEX_SIZE, BaseMeshShim.test_getVertexBufferLength(baseMesh));
+    }
+
+    @Test(timeout = 5000)
+    public void testMeshWithTwoDiv() throws InterruptedException {
+        Util.runAndWait(() -> {
+            Scene scene = myApp.primaryStage.getScene();
+            buildTriangleMesh(myApp.meshView, 2, 2, meshScale);
+        });
+        Thread.sleep(SLEEP_TIME);
+
+        NGTriangleMesh ngTriMesh = TriangleMeshShim.getNGMesh(myApp.meshView.getMesh());
+        assertNotNull(ngTriMesh);
+        BaseMesh baseMesh = NGTriangleMeshShim.test_getMesh(ngTriMesh);
+        assertNotNull(baseMesh);
+        // mesh with 24 vertices (8 triangles)
+        assertEquals(24, BaseMeshShim.test_getNumberOfVertices(baseMesh));
+        // vertexBuffer started with 9 vertices and grew by 6, 3 times, to a
+        // capacity of 27 vertices (27 * VERTEX_SIZE = 243)
+        assertEquals(27 * VERTEX_SIZE, BaseMeshShim.test_getVertexBufferLength(baseMesh));
+    }
+
+    @Test(timeout = 5000)
+    public void testMeshWithThreeDiv() throws InterruptedException {
+        Util.runAndWait(() -> {
+            Scene scene = myApp.primaryStage.getScene();
+            buildTriangleMesh(myApp.meshView, 7, 7, meshScale);
+        });
+        Thread.sleep(SLEEP_TIME);
+
+        NGTriangleMesh ngTriMesh = TriangleMeshShim.getNGMesh(myApp.meshView.getMesh());
+        assertNotNull(ngTriMesh);
+        BaseMesh baseMesh = NGTriangleMeshShim.test_getMesh(ngTriMesh);
+        assertNotNull(baseMesh);
+        // mesh with 294 vertices (98 triangles)
+        assertEquals(294, BaseMeshShim.test_getNumberOfVertices(baseMesh));
+        // vertexBuffer started with 64 vertices and grew by 6 the first time
+        // then crossed over to 12.5% growth rate at each subsequence increase
+        // to a capacity of 325 vertices (325 * VERTEX_SIZE = 2925)
+        assertEquals(325 * VERTEX_SIZE, BaseMeshShim.test_getVertexBufferLength(baseMesh));
+    }
+
+    @Test(timeout = 5000)
+    public void testMeshWithFiveDiv() throws InterruptedException {
+        Util.runAndWait(() -> {
+            Scene scene = myApp.primaryStage.getScene();
+            buildTriangleMesh(myApp.meshView, 50, 50, meshScale);
+        });
+        Thread.sleep(SLEEP_TIME);
+
+        NGTriangleMesh ngTriMesh = TriangleMeshShim.getNGMesh(myApp.meshView.getMesh());
+        assertNotNull(ngTriMesh);
+        BaseMesh baseMesh = NGTriangleMeshShim.test_getMesh(ngTriMesh);
+        assertNotNull(baseMesh);
+        // mesh with 15000 vertices (5000 triangles)
+        assertEquals(15000, BaseMeshShim.test_getNumberOfVertices(baseMesh));
+        // vertexBuffer started with 2601 vertices and grew at 12.5% growth rate
+        // at each subsequence increase to a capacity of 15201 vertices
+        // (15201 * VERTEX_SIZE = 136809)
+        assertEquals(15201 * VERTEX_SIZE, BaseMeshShim.test_getVertexBufferLength(baseMesh));
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/system/src/test/java/test/com/sun/prism/impl/Vec3f.java	Fri Apr 21 16:47:39 2017 -0700
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.com.sun.prism.impl;
+
+/**
+ * A 3-dimensional, single-precision, floating-point vector.
+ *
+ */
+public class Vec3f {
+
+
+    /**
+     * The x coordinate.
+     */
+    public float x;
+
+    /**
+     * The y coordinate.
+     */
+    public float y;
+
+    /**
+     * The z coordinate.
+     */
+    public float z;
+
+    public Vec3f() { }
+
+    public Vec3f(float x, float y, float z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    public Vec3f(Vec3f v) {
+        this.x = v.x;
+        this.y = v.y;
+        this.z = v.z;
+    }
+
+    public void set(Vec3f v) {
+        this.x = v.x;
+        this.y = v.y;
+        this.z = v.z;
+    }
+
+    public void set(float x, float y, float z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    public final void mul(float s) {
+        this.x *= s;
+        this.y *= s;
+        this.z *= s;
+    }
+
+    /**
+     * Sets the value of this vector to the difference
+     * of vectors t1 and t2 (this = t1 - t2).
+     * @param t1 the first vector
+     * @param t2 the second vector
+     */
+    public void sub(Vec3f t1, Vec3f t2) {
+        this.x = t1.x - t2.x;
+        this.y = t1.y - t2.y;
+        this.z = t1.z - t2.z;
+    }
+
+    /**
+     * Sets the value of this vector to the difference of
+     * itself and vector t1 (this = this - t1) .
+     * @param t1 the other vector
+     */
+    public void sub(Vec3f t1) {
+        this.x -= t1.x;
+        this.y -= t1.y;
+        this.z -= t1.z;
+    }
+
+    /**
+     * Sets the value of this vector to the sum
+     * of vectors t1 and t2 (this = t1 + t2).
+     * @param t1 the first vector
+     * @param t2 the second vector
+     */
+    public void add(Vec3f t1, Vec3f t2) {
+        this.x = t1.x + t2.x;
+        this.y = t1.y + t2.y;
+        this.z = t1.z + t2.z;
+    }
+
+    /**
+     * Sets the value of this vector to the sum of
+     * itself and vector t1 (this = this + t1) .
+     * @param t1 the other vector
+     */
+    public void add(Vec3f t1) {
+        this.x += t1.x;
+        this.y += t1.y;
+        this.z += t1.z;
+    }
+
+    /**
+     * Returns the length of this vector.
+     * @return the length of this vector
+     */
+    public float length() {
+        return (float) Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
+    }
+
+    /**
+     * Normalize this vector.
+     */
+    public void normalize() {
+        float norm = 1.0f / length();
+        this.x = this.x * norm;
+        this.y = this.y * norm;
+        this.z = this.z * norm;
+    }
+
+    /**
+     * Sets this vector to be the vector cross product of vectors v1 and v2.
+     * @param v1 the first vector
+     * @param v2 the second vector
+     */
+    public void cross(Vec3f v1, Vec3f v2) {
+        float tmpX;
+        float tmpY;
+
+        tmpX = v1.y * v2.z - v1.z * v2.y;
+        tmpY = v2.x * v1.z - v2.z * v1.x;
+        this.z = v1.x * v2.y - v1.y * v2.x;
+        this.x = tmpX;
+        this.y = tmpY;
+    }
+
+    /**
+     * Computes the dot product of this vector and vector v1.
+     * @param v1 the other vector
+     * @return the dot product of this vector and v1
+     */
+    public float dot(Vec3f v1) {
+        return this.x * v1.x + this.y * v1.y + this.z * v1.z;
+    }
+
+    /**
+     * Returns the hashcode for this <code>Vec3f</code>.
+     * @return      a hash code for this <code>Vec3f</code>.
+     */
+    @Override
+    public int hashCode() {
+        int bits = 7;
+        bits = 31 * bits + Float.floatToIntBits(x);
+        bits = 31 * bits + Float.floatToIntBits(y);
+        bits = 31 * bits + Float.floatToIntBits(z);
+        return bits;
+    }
+
+    /**
+     * Determines whether or not two 3D points or vectors are equal.
+     * Two instances of <code>Vec3f</code> are equal if the values of their
+     * <code>x</code>, <code>y</code> and <code>z</code> member fields,
+     * representing their position in the coordinate space, are the same.
+     * @param obj an object to be compared with this <code>Vec3f</code>
+     * @return <code>true</code> if the object to be compared is
+     *         an instance of <code>Vec3f</code> and has
+     *         the same values; <code>false</code> otherwise.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (obj instanceof Vec3f) {
+            Vec3f v = (Vec3f) obj;
+            return (x == v.x) && (y == v.y) && (z == v.z);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a <code>String</code> that represents the value
+     * of this <code>Vec3f</code>.
+     * @return a string representation of this <code>Vec3f</code>.
+     */
+    @Override
+    public String toString() {
+        return "Vec3f[" + x + ", " + y + ", " + z + "]";
+    }
+}
+