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