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 */
013 package org.jikesrvm.mm.mmtk;
014
015 import org.vmutil.options.OptionSet;
016 import org.mmtk.utility.gcspy.Color;
017 import org.mmtk.utility.gcspy.drivers.AbstractDriver;
018 import org.mmtk.vm.ReferenceProcessor.Semantics;
019
020 import 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 */
028 public 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 /**
034 * Create or retrieve the OptionSet used for MMTk options.
035 *
036 * @return A concrete VM-specific OptionSet instance
037 */
038 public OptionSet getOptionSet() {
039 return org.jikesrvm.options.OptionSet.gc;
040 }
041
042 /**
043 * Create a new ActivePlan instance using the appropriate VM-specific
044 * concrete ActivePlan sub-class.
045 *
046 * @see ActivePlan
047 * @return A concrete VM-specific ActivePlan instance.
048 */
049 public org.mmtk.vm.ActivePlan newActivePlan() {
050 try {
051 return new ActivePlan();
052 } catch (Exception e) {
053 VM.sysFail("Failed to allocate new ActivePlan!");
054 return null; // never get here
055 }
056 }
057
058 /**
059 * Create a new Assert instance using the appropriate VM-specific
060 * concrete Assert sub-class.
061 *
062 * @see Assert
063 * @return A concrete VM-specific Assert instance.
064 */
065 public org.mmtk.vm.Assert newAssert() {
066 try {
067 return new Assert();
068 } catch (Exception e) {
069 VM.sysFail("Failed to allocate new Assert!");
070 return null; // never get here
071 }
072 }
073
074 /**
075 * Create a new Barriers instance using the appropriate VM-specific
076 * concrete Barriers sub-class.
077 *
078 * @see Barriers
079 * @return A concrete VM-specific Barriers instance.
080 */
081 public org.mmtk.vm.Barriers newBarriers() {
082 try {
083 return new Barriers();
084 } catch (Exception e) {
085 VM.sysFail("Failed to allocate new Barriers!");
086 return null; // never get here
087 }
088 }
089
090 /**
091 * Create a new Collection instance using the appropriate VM-specific
092 * concrete Collection sub-class.
093 *
094 * @see Collection
095 * @return A concrete VM-specific Collection instance.
096 */
097 public org.mmtk.vm.Collection newCollection() {
098 try {
099 return new Collection();
100 } catch (Exception e) {
101 VM.sysFail("Failed to allocate new Collection!");
102 return null; // never get here
103 }
104 }
105
106 /**
107 * Create a new BuildTimeConfig instance using the appropriate VM-specific
108 * concrete BuildTimeConfig sub-class.
109 *
110 * @see Collection
111 * @return A concrete VM-specific Collection instance.
112 */
113 public org.mmtk.vm.BuildTimeConfig newBuildTimeConfig() {
114 try {
115 return new BuildTimeConfig(CONFIG_FILE_PROPERTY, DEFAULT_MMTK_PROPERTIES);
116 } catch (Exception e) {
117 VM.sysFail("Failed to allocate new BuildTimeConfiguration!");
118 return null; // never get here
119 }
120 }
121
122 /**
123 * Create a new Lock instance using the appropriate VM-specific
124 * concrete Lock sub-class.
125 *
126 * @see Lock
127 *
128 * @param name The string to be associated with this lock instance
129 * @return A concrete VM-specific Lock instance.
130 */
131 public org.mmtk.vm.Lock newLock(String name) {
132 try {
133 return new Lock(name);
134 } catch (Exception e) {
135 VM.sysFail("Failed to allocate new Lock!");
136 return null; // never get here
137 }
138 }
139
140 /**
141 * Create a new Memory instance using the appropriate VM-specific
142 * concrete Memory sub-class.
143 *
144 * @see Memory
145 * @return A concrete VM-specific Memory instance.
146 */
147 public org.mmtk.vm.Memory newMemory() {
148 try {
149 return new Memory();
150 } catch (Exception e) {
151 VM.sysFail("Failed to allocate new Memory!");
152 return null; // never get here
153 }
154 }
155
156 /**
157 * Create a new ObjectModel instance using the appropriate VM-specific
158 * concrete ObjectModel sub-class.
159 *
160 * @see ObjectModel
161 * @return A concrete VM-specific ObjectModel instance.
162 */
163 public org.mmtk.vm.ObjectModel newObjectModel() {
164 try {
165 return new ObjectModel();
166 } catch (Exception e) {
167 VM.sysFail("Failed to allocate new ObjectModel!");
168 return null; // never get here
169 }
170 }
171
172 /**
173 * Create a new ReferenceProcessor instance using the appropriate VM-specific
174 * concrete ReferenceProcessor sub-class.
175 *
176 * @see ReferenceProcessor
177 * @return A concrete VM-specific ReferenceProcessor instance.
178 */
179 public org.mmtk.vm.ReferenceProcessor newReferenceProcessor(Semantics semantics) {
180 try {
181 return ReferenceProcessor.get(semantics);
182 } catch (Exception e) {
183 VM.sysFail("Failed to allocate new ReferenceProcessor!");
184 return null; // never get here
185 }
186 }
187
188 /**
189 * Create a new FinalizableProcessor instance using the appropriate VM-specific
190 * concrete FinalizableProcessor sub-class.
191 *
192 * @see ReferenceProcessor
193 * @return A concrete VM-specific FinalizableProcessor instance.
194 */
195 public org.mmtk.vm.FinalizableProcessor newFinalizableProcessor() {
196 try {
197 return FinalizableProcessor.getProcessor();
198 } catch (Exception e) {
199 VM.sysFail("Failed to allocate new FinalizableProcessor!");
200 return null; // never get here
201 }
202 }
203
204 /**
205 * Create a new Scanning instance using the appropriate VM-specific
206 * concrete Scanning sub-class.
207 *
208 * @see Scanning
209 * @return A concrete VM-specific Scanning instance.
210 */
211 public org.mmtk.vm.Scanning newScanning() {
212 try {
213 return new Scanning();
214 } catch (Exception e) {
215 VM.sysFail("Failed to allocate new Scanning!");
216 return null; // never get here
217 }
218 }
219
220 /**
221 * Create a new Statistics instance using the appropriate VM-specific
222 * concrete Statistics sub-class.
223 *
224 * @see Statistics
225 * @return A concrete VM-specific Statistics instance.
226 */
227 public org.mmtk.vm.Statistics newStatistics() {
228 try {
229 return new Statistics();
230 } catch (Exception e) {
231 VM.sysFail("Failed to allocate new Statistics!");
232 return null; // never get here
233 }
234 }
235
236 /**
237 * Create a new Strings instance using the appropriate VM-specific
238 * concrete Strings sub-class.
239 *
240 * @see Strings
241 * @return A concrete VM-specific Strings instance.
242 */
243 public org.mmtk.vm.Strings newStrings() {
244 try {
245 return new Strings();
246 } catch (Exception e) {
247 VM.sysFail("Failed to allocate new Strings!");
248 return null; // never get here
249 }
250 }
251
252 /**
253 * Create a new SynchronizedCounter instance using the appropriate
254 * VM-specific concrete SynchronizedCounter sub-class.
255 *
256 * @see SynchronizedCounter
257 *
258 * @return A concrete VM-specific SynchronizedCounter instance.
259 */
260 public org.mmtk.vm.SynchronizedCounter newSynchronizedCounter() {
261 try {
262 return new SynchronizedCounter();
263 } catch (Exception e) {
264 VM.sysFail("Failed to allocate new SynchronizedCounter!");
265 return null; // never get here
266 }
267 }
268
269 /**
270 * Create a new TraceInterface instance using the appropriate VM-specific
271 * concrete TraceInterface sub-class.
272 *
273 * @see TraceInterface
274 * @return A concrete VM-specific TraceInterface instance.
275 */
276 public org.mmtk.vm.TraceInterface newTraceInterface() {
277 try {
278 return new TraceInterface();
279 } catch (Exception e) {
280 VM.sysFail("Failed to allocate new TraceInterface!");
281 return null; // never get here
282 }
283 }
284
285 /**
286 * Create a new MMTk_Events instance using the appropriate VM-specific
287 * concrete MMTk_Events sub-class.
288 *
289 * @see MMTk_Events
290 * @return A concrete VM-specific MMTk_Events instance.
291 */
292 public org.mmtk.vm.MMTk_Events newEvents() {
293 try {
294 return new MMTk_Events(org.jikesrvm.tuningfork.TraceEngine.engine);
295 } catch (Exception e) {
296 VM.sysFail("Failed to allocate new MMTk_Events!");
297 return null; // never get here
298 }
299 }
300
301 public org.mmtk.vm.Debug newDebug() {
302 return new Debug();
303 }
304
305 /**********************************************************************
306 * GCspy methods
307 */
308
309 /**
310 * Create a new Util instance using the appropriate VM-specific
311 * concrete Util sub-class.
312 *
313 * @see org.mmtk.vm.gcspy.Util
314 * @return A concrete VM-specific Util instance.
315 */
316 public org.mmtk.vm.gcspy.Util newGCspyUtil() {
317 try {
318 return new org.jikesrvm.mm.mmtk.gcspy.Util();
319 } catch (Exception e) {
320 VM.sysFail("Failed to allocate new Util!");
321 return null; // never get here
322 }
323 }
324
325 /**
326 * Create a new ServerInterpreter instance using the appropriate VM-specific
327 * concrete ServerInterpreter sub-class.
328 *
329 * @see org.mmtk.vm.gcspy.ServerInterpreter
330 * @return A concrete VM-specific ServerInterpreter instance.
331 */
332 public org.mmtk.vm.gcspy.ServerInterpreter newGCspyServerInterpreter() {
333 try {
334 return new org.jikesrvm.mm.mmtk.gcspy.ServerInterpreter();
335 } catch (Exception e) {
336 VM.sysFail("Failed to allocate new ServerInterpreter!");
337 return null; // never get here
338 }
339 }
340
341 /**
342 * Create a new ServerSpace instance using the appropriate VM-specific
343 * concrete ServerSpace sub-class.
344 *
345 * @param serverInterpreter The server that owns this space
346 * @param serverName The server's name
347 * @param driverName The space driver's name
348 * @param title Title for the space
349 * @param blockInfo A label for each block
350 * @param tileNum Max number of tiles in this space
351 * @param unused A label for unused blocks
352 * @param mainSpace Whether this space is the main space
353 *
354 * @see org.mmtk.vm.gcspy.ServerSpace
355 * @return A concrete VM-specific ServerSpace instance.
356 */
357 public org.mmtk.vm.gcspy.ServerSpace newGCspyServerSpace(
358 org.mmtk.vm.gcspy.ServerInterpreter serverInterpreter,
359 String serverName,
360 String driverName,
361 String title,
362 String blockInfo,
363 int tileNum,
364 String unused,
365 boolean mainSpace){
366 try {
367 return new org.jikesrvm.mm.mmtk.gcspy.ServerSpace(
368 serverInterpreter, serverName, driverName, title,
369 blockInfo, tileNum, unused, mainSpace);
370 } catch (Exception e) {
371 VM.sysFail("Failed to allocate new ServerSpace!");
372 return null; // never get here
373 }
374 }
375
376 /**
377 * Create a new ByteStream instance using the appropriate
378 * VM-specific concrete ByteStream sub-class.
379 *
380 * @param driver The driver that owns this Stream
381 * @param name The name of the stream (e.g. "Used space")
382 * @param minValue The minimum value for any item in this stream.
383 * Values less than this will be represented as "minValue-"
384 * @param maxValue The maximum value for any item in this stream.
385 * Values greater than this will be represented as "maxValue+"
386 * @param zeroValue The zero value for this stream
387 * @param defaultValue The default value for this stream
388 * @param stringPre A string to prefix values (e.g. "Used: ")
389 * @param stringPost A string to suffix values (e.g. " bytes.")
390 * @param presentation How a stream value is to be presented.
391 * @param paintStyle How the value is to be painted.
392 * @param indexMaxStream The index of the maximum stream if the presentation is *_VAR.
393 * @param colour The default colour for tiles of this stream
394 * @see org.mmtk.vm.gcspy.IntStream
395 *
396 * @return A concrete VM-specific ByteStream instance.
397 */
398 public org.mmtk.vm.gcspy.ByteStream newGCspyByteStream(
399 AbstractDriver driver,
400 String name,
401 byte minValue,
402 byte maxValue,
403 byte zeroValue,
404 byte defaultValue,
405 String stringPre,
406 String stringPost,
407 int presentation,
408 int paintStyle,
409 int indexMaxStream,
410 Color colour,
411 boolean summary) {
412 try {
413 return new org.jikesrvm.mm.mmtk.gcspy.ByteStream(
414 driver, name, minValue, maxValue,
415 zeroValue, defaultValue, stringPre, stringPost,
416 presentation, paintStyle, indexMaxStream,
417 colour, summary);
418 } catch (Exception e) {
419 VM.sysFail("Failed to allocate new ByteStream!");
420 return null; // never get here
421 }
422 }
423 /**
424 * Create a new IntStream instance using the appropriate
425 * VM-specific concrete IntStream sub-class.
426 *
427 * @param driver The driver that owns this Stream
428 * @param name The name of the stream (e.g. "Used space")
429 * @param minValue The minimum value for any item in this stream.
430 * Values less than this will be represented as "minValue-"
431 * @param maxValue The maximum value for any item in this stream.
432 * Values greater than this will be represented as "maxValue+"
433 * @param zeroValue The zero value for this stream
434 * @param defaultValue The default value for this stream
435 * @param stringPre A string to prefix values (e.g. "Used: ")
436 * @param stringPost A string to suffix values (e.g. " bytes.")
437 * @param presentation How a stream value is to be presented.
438 * @param paintStyle How the value is to be painted.
439 * @param indexMaxStream The index of the maximum stream if the presentation is *_VAR.
440 * @param colour The default colour for tiles of this stream
441 * @see org.mmtk.vm.gcspy.IntStream
442 *
443 * @return A concrete VM-specific IntStream instance.
444 */
445 public org.mmtk.vm.gcspy.IntStream newGCspyIntStream(
446 AbstractDriver driver,
447 String name,
448 int minValue,
449 int maxValue,
450 int zeroValue,
451 int defaultValue,
452 String stringPre,
453 String stringPost,
454 int presentation,
455 int paintStyle,
456 int indexMaxStream,
457 Color colour,
458 boolean summary) {
459 try {
460 return new org.jikesrvm.mm.mmtk.gcspy.IntStream(
461 driver, name, minValue, maxValue,
462 zeroValue, defaultValue, stringPre, stringPost,
463 presentation, paintStyle, indexMaxStream,
464 colour, summary);
465 } catch (Exception e) {
466 VM.sysFail("Failed to allocate new IntStream!");
467 return null; // never get here
468 }
469 }
470
471 /**
472 * Create a new ShortStream instance using the appropriate
473 * VM-specific concrete ShortStream sub-class.
474 *
475 * @param driver The driver that owns this Stream
476 * @param name The name of the stream (e.g. "Used space")
477 * @param minValue The minimum value for any item in this stream.
478 * Values less than this will be represented as "minValue-"
479 * @param maxValue The maximum value for any item in this stream.
480 * Values greater than this will be represented as "maxValue+"
481 * @param zeroValue The zero value for this stream
482 * @param defaultValue The default value for this stream
483 * @param stringPre A string to prefix values (e.g. "Used: ")
484 * @param stringPost A string to suffix values (e.g. " bytes.")
485 * @param presentation How a stream value is to be presented.
486 * @param paintStyle How the value is to be painted.
487 * @param indexMaxStream The index of the maximum stream if the presentation is *_VAR.
488 * @param colour The default colour for tiles of this stream
489 * @see org.mmtk.vm.gcspy.IntStream
490 *
491 * @return A concrete VM-specific ShortStream instance.
492 */
493 public org.mmtk.vm.gcspy.ShortStream newGCspyShortStream(
494 AbstractDriver driver,
495 String name,
496 short minValue,
497 short maxValue,
498 short zeroValue,
499 short defaultValue,
500 String stringPre,
501 String stringPost,
502 int presentation,
503 int paintStyle,
504 int indexMaxStream,
505 Color colour,
506 boolean summary) {
507 try {
508 return new org.jikesrvm.mm.mmtk.gcspy.ShortStream(
509 driver, name, minValue, maxValue,
510 zeroValue, defaultValue, stringPre, stringPost,
511 presentation, paintStyle, indexMaxStream,
512 colour, summary);
513 } catch (Exception e) {
514 VM.sysFail("Failed to allocate new ShortStream!");
515 return null; // never get here
516 }
517 }
518 }