annotate graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/CompilerImpl.java @ 2874:d90bf514d647

Renamed packages.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 08:59:54 +0200
parents graal/com.oracle.max.graal.runtime/src/com/oracle/graal/runtime/CompilerImpl.java@0341b6424579
children 224412c24426
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
2502
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
2502
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
7 * published by the Free Software Foundation.
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
2502
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
13 * accompanied this code).
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
2502
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
15 * You should have received a copy of the GNU General Public License version
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
2502
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
3e3e8bd12730 Copyright rebranding. Update checkstyle file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 2501
diff changeset
21 * questions.
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
2874
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
23 package com.oracle.max.graal.runtime;
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.io.*;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import java.lang.management.*;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import java.net.*;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
2677
0ea5f12e873a use com.oracle.max.asm project for assembler
Christian.Wimmer@Oracle.com
parents: 2509
diff changeset
29 import com.oracle.max.asm.target.amd64.*;
2874
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
30 import com.oracle.max.graal.compiler.*;
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
31 import com.oracle.max.graal.runtime.logging.*;
d90bf514d647 Renamed packages.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2872
diff changeset
32 import com.oracle.max.graal.runtime.server.*;
2501
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 import com.sun.cri.ci.*;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.sun.cri.ri.*;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 import com.sun.cri.xir.*;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 /**
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 * Singleton class holding the instance of the C1XCompiler.
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 */
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 public final class CompilerImpl implements Compiler, Remote {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 private static Compiler theInstance;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 private static boolean PrintGCStats = false;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 public static Compiler getInstance() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 return theInstance;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 public static void initialize() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 if (theInstance != null) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 throw new IllegalStateException("Compiler already initialized");
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 String remote = System.getProperty("c1x.remote");
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 if (remote != null) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 // remote compilation (will not create a local Compiler)
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 try {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 System.out.println("C1X compiler started in client/server mode, server: " + remote);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 Socket socket = new Socket(remote, 1199);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 ReplacingStreams streams = new ReplacingStreams(socket.getOutputStream(), socket.getInputStream());
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 streams.getInvocation().sendResult(new VMEntriesNative());
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 theInstance = (Compiler) streams.getInvocation().waitForResult(false);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 } catch (IOException e1) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 System.out.println("Connection to compilation server FAILED.");
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 throw new RuntimeException(e1);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 } catch (ClassNotFoundException e2) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 System.out.println("Connection to compilation server FAILED.");
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 throw new RuntimeException(e2);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 } else {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 // ordinary local compilation
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 theInstance = new CompilerImpl(null);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 Runtime.getRuntime().addShutdownHook(new ShutdownThread());
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 public static Compiler initializeServer(VMEntries entries) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 assert theInstance == null;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 theInstance = new CompilerImpl(entries);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 Runtime.getRuntime().addShutdownHook(new ShutdownThread());
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 return theInstance;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 public static class ShutdownThread extends Thread {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 @Override
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 public void run() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 VMExitsNative.compileMethods = false;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 if (C1XOptions.PrintMetrics) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 C1XMetrics.print();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 if (C1XOptions.PrintTimers) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 C1XTimers.print();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 if (PrintGCStats) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 printGCStats();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 public static void printGCStats() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 long totalGarbageCollections = 0;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 long garbageCollectionTime = 0;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 long count = gc.getCollectionCount();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 if (count >= 0) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 totalGarbageCollections += count;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 long time = gc.getCollectionTime();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 if (time >= 0) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 garbageCollectionTime += time;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 System.out.println("Total Garbage Collections: " + totalGarbageCollections);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 System.out.println("Total Garbage Collection Time (ms): " + garbageCollectionTime);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 private final VMEntries vmEntries;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 private final VMExits vmExits;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 private C1XCompiler compiler;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 private final HotSpotRuntime runtime;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 private final CiTarget target;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 private final RiXirGenerator generator;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 private final RiRegisterConfig registerConfig;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 private CompilerImpl(VMEntries entries) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 // initialize VMEntries
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 if (entries == null) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 entries = new VMEntriesNative();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 // initialize VMExits
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 VMExits exits = new VMExitsNative(this);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 // logging, etc.
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 if (CountingProxy.ENABLED) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 exits = CountingProxy.getProxy(VMExits.class, exits);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 entries = CountingProxy.getProxy(VMEntries.class, entries);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 if (Logger.ENABLED) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 exits = LoggingProxy.getProxy(VMExits.class, exits);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 entries = LoggingProxy.getProxy(VMEntries.class, entries);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 // set the final fields
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 vmEntries = entries;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 vmExits = exits;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 // initialize compiler and C1XOptions
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 HotSpotVMConfig config = vmEntries.getConfiguration();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 config.check();
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
158
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 // these options are important - c1x4hotspot will not generate correct code without them
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 C1XOptions.GenSpecialDivChecks = true;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 C1XOptions.NullCheckUniquePc = true;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 C1XOptions.InvokeSnippetAfterArguments = true;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 C1XOptions.StackShadowPages = config.stackShadowPages;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 runtime = new HotSpotRuntime(config, this);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 registerConfig = runtime.globalStubRegConfig;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 final int wordSize = 8;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
169 final int stackFrameAlignment = 16;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 target = new HotSpotTarget(new AMD64(), true, wordSize, stackFrameAlignment, config.vmPageSize, wordSize, true);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 RiXirGenerator generator = new HotSpotXirGenerator(config, target, registerConfig, this);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 if (Logger.ENABLED) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 this.generator = LoggingProxy.getProxy(RiXirGenerator.class, generator);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 } else {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 this.generator = generator;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 @Override
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 public C1XCompiler getCompiler() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 if (compiler == null) {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 compiler = new C1XCompiler(runtime, target, generator, registerConfig);
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
186 return compiler;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189 @Override
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
190 public VMEntries getVMEntries() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 return vmEntries;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
192 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 @Override
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 public VMExits getVMExits() {
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 return vmExits;
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 }
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198
6594e6d8bfe7 Rebranding to com.oracle.graal
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 }