Fri, 05 Jul 2013 14:36:54 +0200
8017084: Use spill properties for large object literals
Reviewed-by: lagergren, sundar
attila@175 | 1 | /* |
attila@175 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
attila@175 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
attila@175 | 4 | * |
attila@175 | 5 | * This code is free software; you can redistribute it and/or modify it |
attila@175 | 6 | * under the terms of the GNU General Public License version 2 only, as |
attila@175 | 7 | * published by the Free Software Foundation. |
attila@175 | 8 | * |
attila@175 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
attila@175 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
attila@175 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
attila@175 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
attila@175 | 13 | * accompanied this code). |
attila@175 | 14 | * |
attila@175 | 15 | * You should have received a copy of the GNU General Public License version |
attila@175 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
attila@175 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
attila@175 | 18 | * |
attila@175 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
attila@175 | 20 | * or visit www.oracle.com if you need additional information or have any |
attila@175 | 21 | * questions. |
attila@175 | 22 | */ |
attila@175 | 23 | |
attila@175 | 24 | /** |
attila@175 | 25 | * Check behavior of class-level overrides. |
attila@175 | 26 | * |
attila@175 | 27 | * @test |
attila@175 | 28 | * @run |
attila@175 | 29 | */ |
attila@175 | 30 | |
attila@175 | 31 | |
attila@175 | 32 | // Make two classes with class overrides |
attila@175 | 33 | |
attila@175 | 34 | var R1 = Java.extend(java.lang.Runnable, { |
attila@175 | 35 | run: function() { |
attila@175 | 36 | print("R1.run() invoked") |
attila@175 | 37 | } |
attila@175 | 38 | }) |
attila@175 | 39 | |
attila@175 | 40 | var R2 = Java.extend(java.lang.Runnable, { |
attila@175 | 41 | run: function() { |
attila@175 | 42 | print("R2.run() invoked") |
attila@175 | 43 | } |
attila@175 | 44 | }) |
attila@175 | 45 | |
attila@175 | 46 | var r1 = new R1 |
attila@175 | 47 | var r2 = new R2 |
attila@175 | 48 | // Create one with an instance-override too |
attila@175 | 49 | var r3 = new R2(function() { print("r3.run() invoked") }) |
attila@175 | 50 | |
attila@175 | 51 | // Run 'em - we're passing them through a Thread to make sure they indeed |
attila@175 | 52 | // are full-blown Runnables |
attila@175 | 53 | function runInThread(r) { |
attila@175 | 54 | var t = new java.lang.Thread(r) |
attila@175 | 55 | t.start() |
attila@175 | 56 | t.join() |
attila@175 | 57 | } |
attila@175 | 58 | runInThread(r1) |
attila@175 | 59 | runInThread(r2) |
attila@175 | 60 | runInThread(r3) |
attila@175 | 61 | |
attila@175 | 62 | // Two class-override classes differ |
attila@175 | 63 | print("r1.class != r2.class: " + (r1.class != r2.class)) |
attila@175 | 64 | // However, adding instance-overrides doesn't change the class |
attila@175 | 65 | print("r2.class == r3.class: " + (r2.class == r3.class)) |
attila@175 | 66 | |
attila@175 | 67 | function checkAbstract(r) { |
attila@175 | 68 | try { |
attila@175 | 69 | r.run() |
attila@175 | 70 | print("Expected to fail!") |
attila@175 | 71 | } catch(e) { |
attila@175 | 72 | print("Got exception: " + e) |
attila@175 | 73 | } |
attila@175 | 74 | } |
attila@175 | 75 | |
attila@175 | 76 | // Check we're hitting UnsupportedOperationException if neither class |
attila@175 | 77 | // overrides nor instance overrides are present |
attila@175 | 78 | var RAbstract = Java.extend(java.lang.Runnable, {}) |
attila@175 | 79 | checkAbstract(new RAbstract()) // class override (empty) |
attila@175 | 80 | checkAbstract(new RAbstract() {}) // class+instance override (empty) |
attila@175 | 81 | |
attila@175 | 82 | // Check we delegate to superclass if neither class |
attila@175 | 83 | // overrides nor instance overrides are present |
attila@175 | 84 | var ExtendsList = Java.extend(java.util.ArrayList, {}) |
attila@175 | 85 | print("(new ExtendsList).size() = " + (new ExtendsList).size()) |
attila@175 | 86 | print("(new ExtendsList(){}).size() = " + (new ExtendsList(){}).size()) |