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.mmtk.utility.gcspy;
014
015 import org.mmtk.utility.Log;
016 import org.mmtk.utility.options.*;
017 import org.mmtk.vm.VM;
018 import org.mmtk.vm.gcspy.ServerInterpreter;
019 import org.mmtk.vm.gcspy.Util;
020
021 import org.vmmagic.pragma.*;
022
023 /**
024 * This class implements collector-independent GCspy functionality to start
025 * the GCspy server. It handles command-line parameters for port number,
026 * whether the VM should wait for a GCspy client to connect, and tile size.
027 * Most importantly, it calls the Plan's startGCspyServer method which
028 * creates a new ServerInterpreter, and adds events and space drivers.
029 */
030 @Uninterruptible public class GCspy {
031
032 /****************************************************************************
033 *
034 * Class variables
035 */
036
037 /**
038 *
039 */
040 public static final Util util = VM.newGCspyUtil();
041 public static final ServerInterpreter server = VM.newGCspyServerInterpreter();
042
043 /****************************************************************************
044 *
045 * Initialization
046 */
047
048 /**
049 *
050 */
051 @Interruptible
052 public static void createOptions() {
053 Options.gcspyPort = new GCspyPort();
054 Options.gcspyWait = new GCspyWait();
055 Options.gcspyTileSize = new GCspyTileSize();
056 }
057
058 /**
059 * Get the number of the port that GCspy communicates on
060 *
061 * @return the GCspy port number
062 */
063 public static int getGCspyPort() {
064 return Options.gcspyPort.getValue();
065 }
066
067 /**
068 * Should the VM wait for GCspy to connect?
069 *
070 * @return whether the VM should wait for the visualiser to connect
071 */
072 public static boolean getGCspyWait() {
073 return Options.gcspyWait.getValue();
074 }
075
076 /**
077 * Start the GCspy server.
078 * WARNING: allocates memory indirectly
079 */
080 @Interruptible
081 public static void startGCspyServer() {
082 int port = getGCspyPort();
083 Log.write("GCspy.startGCspyServer, port="); Log.write(port);
084 Log.write(", wait=");
085 Log.writeln(getGCspyWait());
086 if (port > 0) {
087 VM.activePlan.global().startGCspyServer(port, getGCspyWait());
088 //Log.writeln("gcspy thread booted");
089 }
090 }
091 }
092