2442N/A/*
2442N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2442N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2442N/A *
2442N/A * This code is free software; you can redistribute it and/or modify it
2442N/A * under the terms of the GNU General Public License version 2 only, as
2442N/A * published by the Free Software Foundation.
2442N/A *
2442N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2442N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2442N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2442N/A * version 2 for more details (a copy is included in the LICENSE file that
2442N/A * accompanied this code).
2442N/A *
2442N/A * You should have received a copy of the GNU General Public License version
2442N/A * 2 along with this work; if not, write to the Free Software Foundation,
2442N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2442N/A *
2442N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2442N/A * or visit www.oracle.com if you need additional information or have any
2442N/A * questions.
2442N/A *
2442N/A */
2442N/A
2442N/A/**
2442N/A * @test
2442N/A * @bug 6357214
2442N/A * @summary Hotspot server compiler gets integer comparison wrong
2442N/A *
2442N/A * @run main/othervm/timeout=60 -DshowAll=ffo -DeventID=444 Test6357214
2442N/A */
2442N/A
2442N/A// The test hangs after few iterations before the fix. So it fails if timeout.
2442N/Aclass MyResult {
2442N/A public boolean next() {
2442N/A return true;
2442N/A }
2442N/A
2442N/A public String getString(String in) {
2442N/A if (in.equals("id"))
2442N/A return "idFoo";
2442N/A if (in.equals("contentKey"))
2442N/A return "ckFoo";
2442N/A return "Foo";
2442N/A }
2442N/A
2442N/A public int getInt(String in) {
2442N/A if (in.equals("processingComplete"))
2442N/A return 0;
2442N/A return 1;
2442N/A }
2442N/A
2442N/A public byte[] getBytes(String in) {
2442N/A byte[] arr = null;
2442N/A if (in.equals("content")) {
2442N/A arr = new byte[65536];
2442N/A byte j = 32;
2442N/A for (int i=0; i<65536; i++) {
2442N/A arr[i] = j;
2442N/A if (++j == 127)
2442N/A j=32;
2442N/A }
2442N/A }
2442N/A return arr;
2442N/A }
2442N/A}
2442N/A
2442N/Apublic class Test6357214 {
2442N/A public static volatile boolean bollocks = true;
2442N/A public String create(String context) throws Exception {
2442N/A
2442N/A //
2442N/A // Extract HTTP parameters
2442N/A //
2442N/A
2442N/A boolean showAll = System.getProperty("showAll") != null;
2442N/A String eventID = System.getProperty("eventID");
2442N/A String eventContentKey = System.getProperty("cKey");
2442N/A //
2442N/A // Build ContentStaging query based on eventID or eventContentKey
2442N/A //
2442N/A
2442N/A String sql = "select id, processingComplete, contentKey, content "
2442N/A + "from ContentStaging cs, ContentStagingKey csk "
2442N/A + "where cs.eventContentKey = csk.eventContentKey ";
2442N/A
2442N/A if (eventID != null) {
2442N/A sql += "and id = " + eventID;
2442N/A }
2442N/A else if (eventContentKey != null) {
2442N/A sql += "and cs.eventContentKey = '"
2442N/A + eventContentKey
2442N/A + "' having id = max(id)";
2442N/A }
2442N/A else {
2442N/A throw new Exception("Need eventID or eventContentKey");
2442N/A }
2442N/A
2442N/A //
2442N/A // This factory builds a static panel, there is no JSP
2442N/A //
2442N/A
2442N/A StringBuffer html = new StringBuffer();
2442N/A
2442N/A try {
2442N/A
2442N/A MyResult result = new MyResult();
2442N/A if (result.next()) {
2442N/A
2442N/A eventID = result.getString("id");
2442N/A int processingComplete = result.getInt("processingComplete");
2442N/A String contentKey = result.getString("contentKey");
2442N/A byte[] bytes = result.getBytes("content");
2442N/A
2442N/A //
2442N/A // Print content status and associated controls
2442N/A //
2442N/A
2442N/A html.append("<br/><font class=\"small\">");
2442N/A html.append("Status: ");
2442N/A switch (processingComplete) {
2442N/A case 0 :
2442N/A case 1 : html.append("PENDING"); break;
2442N/A case 2 : html.append(contentKey); break;
2442N/A case 3 : html.append(eventID); break;
2442N/A default : html.append("UNKNONW");
2442N/A }
2442N/A html.append("</font><br/>");
2442N/A
2442N/A //
2442N/A // Print at most 20Kb of content unless "showAll" is set
2442N/A //
2442N/A
2442N/A int limit = showAll ? Integer.MAX_VALUE : 1024 * 20;
2442N/A System.out.println(limit);
2442N/A html.append("<pre>");
2442N/A for (int i = 0; bytes != null && i < bytes.length; i++) {
2442N/A char c = (char) bytes[i];
2442N/A switch (c) {
2442N/A case '<' : html.append("&lt;"); break;
2442N/A case '>' : html.append("&gt;"); break;
2442N/A case '&' : html.append("&amp;"); break;
2442N/A default : html.append(c);
2442N/A }
2442N/A
2442N/A if (i > limit) {
2442N/A while (bollocks);
2442N/A // System.out.println("i is " + i);
2442N/A // System.out.println("limit is " + limit);
2442N/A html.append("...\n</pre>");
2442N/A html.append(eventID);
2442N/A html.append("<pre>");
2442N/A break;
2442N/A }
2442N/A }
2442N/A html.append("</pre>");
2442N/A }
2442N/A }
2442N/A catch (Exception exception) {
2442N/A throw exception;
2442N/A }
2442N/A finally {
2442N/A html.append("Oof!!");
2442N/A }
2442N/A String ret = html.toString();
2442N/A System.out.println("Returning string length = "+ ret.length());
2442N/A return ret;
2442N/A }
2442N/A
2442N/A public static void main(String[] args) throws Exception {
2442N/A int length=0;
2442N/A
2442N/A for (int i = 0; i < 100; i++) {
2442N/A length = new Test6357214().create("boo").length();
2442N/A System.out.println(length);
2442N/A }
2442N/A }
2442N/A}
2442N/A