001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.mm.mmtk;
014
015import org.vmutil.options.OptionSet;
016import org.mmtk.utility.gcspy.Color;
017import org.mmtk.utility.gcspy.drivers.AbstractDriver;
018import org.mmtk.vm.ReferenceProcessor.Semantics;
019
020import org.jikesrvm.VM;
021
022/**
023 * This is a VM-specific class which defines factory methods for
024 * VM-specific types which must be instantiated within MMTk.
025 *
026 * @see org.mmtk.vm.Factory
027 */
028public final class Factory extends org.mmtk.vm.Factory {
029
030  private static final String DEFAULT_MMTK_PROPERTIES = ".mmtk.properties";
031  private static final String CONFIG_FILE_PROPERTY = "mmtk.properties";
032
033  @Override
034  public OptionSet getOptionSet() {
035    return org.jikesrvm.options.OptionSet.gc;
036  }
037
038  @Override
039  public org.mmtk.vm.ActivePlan newActivePlan() {
040    try {
041      return new ActivePlan();
042    } catch (Exception e) {
043      VM.sysFail("Failed to allocate new ActivePlan!");
044      return null; // never get here
045    }
046  }
047
048  @Override
049  public org.mmtk.vm.Assert newAssert() {
050    try {
051      return new Assert();
052    } catch (Exception e) {
053      VM.sysFail("Failed to allocate new Assert!");
054      return null; // never get here
055    }
056  }
057
058  @Override
059  public org.mmtk.vm.Barriers newBarriers() {
060    try {
061      return new Barriers();
062    } catch (Exception e) {
063      VM.sysFail("Failed to allocate new Barriers!");
064      return null; // never get here
065    }
066  }
067
068  @Override
069  public org.mmtk.vm.Collection newCollection() {
070    try {
071      return new Collection();
072    } catch (Exception e) {
073      VM.sysFail("Failed to allocate new Collection!");
074      return null; // never get here
075    }
076  }
077
078  @Override
079  public org.mmtk.vm.BuildTimeConfig newBuildTimeConfig() {
080    try {
081      return new BuildTimeConfig(CONFIG_FILE_PROPERTY, DEFAULT_MMTK_PROPERTIES);
082    } catch (Exception e) {
083      VM.sysFail("Failed to allocate new BuildTimeConfiguration!");
084      return null; // never get here
085    }
086  }
087
088  @Override
089  public org.mmtk.vm.Lock newLock(String name) {
090    try {
091      return new Lock(name);
092    } catch (Exception e) {
093      VM.sysFail("Failed to allocate new Lock!");
094      return null; // never get here
095    }
096  }
097
098  @Override
099  public org.mmtk.vm.Monitor newMonitor(String name) {
100    try {
101      return new Monitor(name);
102    } catch (Exception e) {
103      VM.sysFail("Failed to allocate new Monitor!");
104      return null; // never get here
105    }
106  }
107
108  @Override
109  public org.mmtk.vm.Memory newMemory() {
110    try {
111      return new Memory();
112    } catch (Exception e) {
113      VM.sysFail("Failed to allocate new Memory!");
114      return null; // never get here
115    }
116  }
117
118  @Override
119  public org.mmtk.vm.ObjectModel newObjectModel() {
120    try {
121      return new ObjectModel();
122    } catch (Exception e) {
123      VM.sysFail("Failed to allocate new ObjectModel!");
124      return null; // never get here
125    }
126  }
127
128  @Override
129  public org.mmtk.vm.ReferenceProcessor newReferenceProcessor(Semantics semantics) {
130    try {
131      return ReferenceProcessor.get(semantics);
132    } catch (Exception e) {
133      VM.sysFail("Failed to allocate new ReferenceProcessor!");
134      return null; // never get here
135    }
136  }
137
138  @Override
139  public org.mmtk.vm.FinalizableProcessor newFinalizableProcessor() {
140    try {
141      return FinalizableProcessor.getProcessor();
142    } catch (Exception e) {
143      VM.sysFail("Failed to allocate new FinalizableProcessor!");
144      return null; // never get here
145    }
146  }
147
148  @Override
149  public org.mmtk.vm.Scanning newScanning() {
150    try {
151      return new Scanning();
152    } catch (Exception e) {
153      VM.sysFail("Failed to allocate new Scanning!");
154      return null; // never get here
155    }
156  }
157
158  @Override
159  public org.mmtk.vm.Statistics newStatistics() {
160    try {
161      return new Statistics();
162    } catch (Exception e) {
163      VM.sysFail("Failed to allocate new Statistics!");
164      return null; // never get here
165    }
166  }
167
168  @Override
169  public org.mmtk.vm.Strings newStrings() {
170    try {
171      return new Strings();
172    } catch (Exception e) {
173      VM.sysFail("Failed to allocate new Strings!");
174      return null; // never get here
175    }
176  }
177
178  @Override
179  public org.mmtk.vm.SynchronizedCounter newSynchronizedCounter() {
180    try {
181      return new SynchronizedCounter();
182    } catch (Exception e) {
183     VM.sysFail("Failed to allocate new SynchronizedCounter!");
184      return null; // never get here
185    }
186  }
187
188  @Override
189  public org.mmtk.vm.TraceInterface newTraceInterface() {
190    try {
191      return new TraceInterface();
192    } catch (Exception e) {
193      VM.sysFail("Failed to allocate new TraceInterface!");
194      return null; // never get here
195    }
196  }
197
198  @Override
199  public org.mmtk.vm.MMTk_Events newEvents() {
200    try {
201      return new MMTk_Events(org.jikesrvm.tuningfork.TraceEngine.engine);
202    } catch (Exception e) {
203      VM.sysFail("Failed to allocate new MMTk_Events!");
204      return null; // never get here
205    }
206  }
207
208  @Override
209  public org.mmtk.vm.Debug newDebug() {
210    return new Debug();
211  }
212
213  /**********************************************************************
214   * GCspy methods
215   */
216
217  /**
218   * {@inheritDoc}
219   */
220  @Override
221  public org.mmtk.vm.gcspy.Util newGCspyUtil() {
222    try {
223      return new org.jikesrvm.mm.mmtk.gcspy.Util();
224    } catch (Exception e) {
225      VM.sysFail("Failed to allocate new Util!");
226      return null; // never get here
227    }
228  }
229
230  @Override
231  public org.mmtk.vm.gcspy.ServerInterpreter newGCspyServerInterpreter() {
232    try {
233      return new org.jikesrvm.mm.mmtk.gcspy.ServerInterpreter();
234    } catch (Exception e) {
235      VM.sysFail("Failed to allocate new ServerInterpreter!");
236      return null; // never get here
237    }
238  }
239
240  @Override
241  public org.mmtk.vm.gcspy.ServerSpace newGCspyServerSpace(
242      org.mmtk.vm.gcspy.ServerInterpreter serverInterpreter,
243      String serverName,
244      String driverName,
245      String title,
246      String blockInfo,
247      int tileNum,
248      String unused,
249      boolean mainSpace) {
250    try {
251      return new org.jikesrvm.mm.mmtk.gcspy.ServerSpace(
252          serverInterpreter, serverName, driverName, title,
253          blockInfo, tileNum, unused, mainSpace);
254    } catch (Exception e) {
255      VM.sysFail("Failed to allocate new ServerSpace!");
256      return null; // never get here
257    }
258  }
259
260  @Override
261  public org.mmtk.vm.gcspy.ByteStream newGCspyByteStream(
262      AbstractDriver driver,
263      String name,
264      byte minValue,
265      byte maxValue,
266      byte zeroValue,
267      byte defaultValue,
268      String stringPre,
269      String stringPost,
270      int presentation,
271      int paintStyle,
272      int indexMaxStream,
273      Color colour,
274      boolean summary) {
275    try {
276      return new org.jikesrvm.mm.mmtk.gcspy.ByteStream(
277          driver, name, minValue,  maxValue,
278          zeroValue, defaultValue, stringPre, stringPost,
279          presentation, paintStyle, indexMaxStream,
280          colour, summary);
281    } catch (Exception e) {
282      VM.sysFail("Failed to allocate new ByteStream!");
283      return null; // never get here
284    }
285  }
286
287  @Override
288  public org.mmtk.vm.gcspy.IntStream newGCspyIntStream(
289      AbstractDriver driver,
290      String name,
291      int minValue,
292      int maxValue,
293      int zeroValue,
294      int defaultValue,
295      String stringPre,
296      String stringPost,
297      int presentation,
298      int paintStyle,
299      int indexMaxStream,
300      Color colour,
301      boolean summary) {
302    try {
303      return new org.jikesrvm.mm.mmtk.gcspy.IntStream(
304          driver, name, minValue,  maxValue,
305          zeroValue, defaultValue, stringPre, stringPost,
306          presentation, paintStyle, indexMaxStream,
307          colour, summary);
308    } catch (Exception e) {
309      VM.sysFail("Failed to allocate new IntStream!");
310      return null; // never get here
311    }
312  }
313
314  @Override
315  public org.mmtk.vm.gcspy.ShortStream newGCspyShortStream(
316      AbstractDriver driver,
317      String name,
318      short minValue,
319      short maxValue,
320      short zeroValue,
321      short defaultValue,
322      String stringPre,
323      String stringPost,
324      int presentation,
325      int paintStyle,
326      int indexMaxStream,
327      Color colour,
328      boolean summary) {
329    try {
330      return new org.jikesrvm.mm.mmtk.gcspy.ShortStream(
331          driver, name, minValue,  maxValue,
332          zeroValue, defaultValue, stringPre, stringPost,
333          presentation, paintStyle, indexMaxStream,
334          colour, summary);
335    } catch (Exception e) {
336      VM.sysFail("Failed to allocate new ShortStream!");
337      return null; // never get here
338    }
339  }
340}