diff options
author | Mathieu Chartier <mathieuc@google.com> | 2015-01-28 13:11:44 -0800 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2015-01-28 14:26:47 -0800 |
commit | e4a91bbeaa118bc01a5c338c6a6d9ee094a6a2c6 (patch) | |
tree | 8ee63aced115823626d614e70716d745f72bb3a6 /test/133-static-invoke-super | |
parent | ab7f56d9b9838811cb01773e45999e2cda4aa03a (diff) | |
download | art-e4a91bbeaa118bc01a5c338c6a6d9ee094a6a2c6.tar.gz art-e4a91bbeaa118bc01a5c338c6a6d9ee094a6a2c6.tar.bz2 art-e4a91bbeaa118bc01a5c338c6a6d9ee094a6a2c6.zip |
Force set resolved method for static invokes
For static invokes, we may dispatch to the static method in the
superclass but resolve using the subclass. To prevent getting slow
paths on each invoke, we force set the resolved method for the
super class dex method index if we are in the same dex file.
Added test.
Bug: 19175856
Change-Id: I26f8644a7f725f5c2dc2a94a8e9578f573792507
Diffstat (limited to 'test/133-static-invoke-super')
-rw-r--r-- | test/133-static-invoke-super/expected.txt | 3 | ||||
-rw-r--r-- | test/133-static-invoke-super/info.txt | 2 | ||||
-rwxr-xr-x | test/133-static-invoke-super/run | 18 | ||||
-rw-r--r-- | test/133-static-invoke-super/src/Main.java | 63 |
4 files changed, 86 insertions, 0 deletions
diff --git a/test/133-static-invoke-super/expected.txt b/test/133-static-invoke-super/expected.txt new file mode 100644 index 0000000000..089d8e85aa --- /dev/null +++ b/test/133-static-invoke-super/expected.txt @@ -0,0 +1,3 @@ +basis: performed 50000000 iterations +test1: performed 50000000 iterations +Timing is acceptable. diff --git a/test/133-static-invoke-super/info.txt b/test/133-static-invoke-super/info.txt new file mode 100644 index 0000000000..606331b5fb --- /dev/null +++ b/test/133-static-invoke-super/info.txt @@ -0,0 +1,2 @@ +This is a performance test of invoking static methods in super class. To see the numbers, invoke +this test with the "--timing" option. diff --git a/test/133-static-invoke-super/run b/test/133-static-invoke-super/run new file mode 100755 index 0000000000..e27a622f40 --- /dev/null +++ b/test/133-static-invoke-super/run @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Copyright (C) 2012 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# As this is a performance test we always use the non-debug build. +exec ${RUN} "${@/#libartd.so/libart.so}" diff --git a/test/133-static-invoke-super/src/Main.java b/test/133-static-invoke-super/src/Main.java new file mode 100644 index 0000000000..7cfd099a53 --- /dev/null +++ b/test/133-static-invoke-super/src/Main.java @@ -0,0 +1,63 @@ + +public class Main { + static class SuperClass { + protected static int getVar(int w) { + return w & 0xF; + } + } + static class SubClass extends SuperClass { + final int getVarDirect(int w) { + return w & 0xF; + } + public void testDirect(int max) { + for (int i = 0; i < max; ++i) { + getVarDirect(max); + } + } + public void testStatic(int max) { + for (int i = 0; i < max; ++i) { + getVar(max); + } + } + } + + static public void main(String[] args) throws Exception { + boolean timing = (args.length >= 1) && args[0].equals("--timing"); + run(timing); + } + + static int testBasis(int interations) { + (new SubClass()).testDirect(interations); + return interations; + } + + static int testStatic(int interations) { + (new SubClass()).testStatic(interations); + return interations; + } + + static public void run(boolean timing) { + long time0 = System.nanoTime(); + int count1 = testBasis(50000000); + long time1 = System.nanoTime(); + int count2 = testStatic(50000000); + long time2 = System.nanoTime(); + + System.out.println("basis: performed " + count1 + " iterations"); + System.out.println("test1: performed " + count2 + " iterations"); + + double basisMsec = (time1 - time0) / (double) count1 / 1000000; + double msec1 = (time2 - time1) / (double) count2 / 1000000; + + if (msec1 < basisMsec * 5) { + System.out.println("Timing is acceptable."); + } else { + System.out.println("Iterations are taking too long!"); + timing = true; + } + if (timing) { + System.out.printf("basis time: %.3g msec\n", basisMsec); + System.out.printf("test1: %.3g msec per iteration\n", msec1); + } + } +} |