annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CounterAndTimeBasedCompilationPolicy.java @ 18858:db0af0d8d623

fixed JVM_GetGraalServiceImpls signature Contributed-by: Igor Ignatyev <igor.ignatyev@oracle.com>
author Doug Simon <doug.simon@oracle.com>
date Tue, 13 Jan 2015 13:12:01 +0100
parents a65c1032f400
children 05183a084a08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.graal.truffle;
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
27 import com.oracle.truffle.api.*;
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
28
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 public class CounterAndTimeBasedCompilationPolicy extends CounterBasedCompilationPolicy {
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
31 @Override
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
32 public boolean shouldCompile(CompilationProfile profile, CompilerOptions options) {
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
33 if (super.shouldCompile(profile, options)) {
18575
a65c1032f400 Truffle: turn milliseconds in nanoseconds for the time threshold after options have been considered.
Chris Seaton <chris.seaton@oracle.com>
parents: 18386
diff changeset
34 long threshold = TruffleTimeThreshold.getValue();
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
36 if (options instanceof GraalCompilerOptions) {
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
37 threshold = Math.max(threshold, ((GraalCompilerOptions) options).getMinTimeThreshold());
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
38 }
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
39
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 long time = profile.getTimestamp();
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 if (time == 0) {
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 throw new AssertionError();
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 }
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 long timeElapsed = System.nanoTime() - time;
18575
a65c1032f400 Truffle: turn milliseconds in nanoseconds for the time threshold after options have been considered.
Chris Seaton <chris.seaton@oracle.com>
parents: 18386
diff changeset
45 if (timeElapsed > threshold * 1_000_000) {
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 profile.deferCompilation();
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 return false;
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 }
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 return true;
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 } else {
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 return false;
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 }
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 }
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 }