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.vm.gcspy;
014    
015    import org.mmtk.utility.Log;
016    import org.mmtk.utility.gcspy.drivers.AbstractDriver;
017    import org.vmmagic.unboxed.*;
018    import org.vmmagic.pragma.*;
019    
020    /**
021     * Abstract class for the GCspy Space abstraction.<p>
022     *
023     * Implementing classes will largely forward calls to the gcspy C library.
024     */
025    @Uninterruptible public abstract class ServerSpace {
026    
027      /****************************************************************************
028       *
029       * Class variables
030       */
031    
032      /** The "unused" string */
033      protected static final String DEFAULT_UNUSED_STRING = "NOT USED";
034    
035      /****************************************************************************
036      *
037      * Instance variables
038      */
039    
040      /** the space's ID */
041      protected int spaceId;
042      /** a pointer to the C driver, {@code gcspy_gc_drivert *driver} */
043      protected Address driver;
044      protected static final boolean DEBUG = false;
045    
046    
047      /**
048       * Get a pointer to the native driver
049       * @return The address of the C driver, {@code gcspy_gc_drivert *}, used in all calls
050       * to the C library.
051       */
052      Address getDriverAddress() {
053        return driver;
054      }
055    
056      /**
057       * Tell the native driver the tile name.
058       * @param i the number of the tile
059       * @param start the starting address of the tile
060       * @param end the end address
061       */
062      public abstract void setTilename(int i, Address start, Address end);
063    
064      /**
065       * Tell the native driver the tile name.
066       * @param i the number of the tile
067       * @param format the name of the tile, a format string
068       * @param value The value for the format string
069       */
070      public abstract void setTilename(int i, Address format, long value);
071    
072      /**
073       * Tell the native driver the tile names.
074       * @param i the number of the tile
075       * @param format The name, including format tags
076       * @param value The value for the format string
077       */
078      public abstract void setTilename(int i, String format, long value);
079    
080      /**
081       * Tell the C driver to resize
082       * @param size the new driver size
083       */
084      public abstract void resize(int size);
085    
086      /**
087       * Start a transmission
088       */
089      public abstract void startCommunication();
090    
091      /**
092       * Add a stream to the native driver
093       * @param id the stream's ID
094       * @return the address of the C {@code gcspy_gc_stream_t}
095       */
096      public abstract Address addStream(int id);
097    
098      /**
099       * Start transmitting a stream.
100       * @param id The stream's ID
101       * @param len The number of items in the stream
102       */
103      public abstract void stream(int id, int len);
104    
105      /**
106       * Send a byte
107       * @param value The byte
108       */
109      public abstract void streamByteValue(byte value);
110    
111      /**
112       * Send a short
113       * @param value The short
114       */
115      public abstract void streamShortValue(short value);
116    
117      /**
118       * Send an int
119       * @param value The int
120       */
121      public abstract void streamIntValue(int value);
122    
123      /**
124       * End of this stream
125       */
126      public abstract void streamEnd();
127    
128      /**
129       * Start to send a summary
130       * @param id The stream's ID
131       * @param len The number of items to be sent
132       */
133      public abstract void summary(int id, int len);
134    
135      /**
136       * Send a summary value
137       * @param val The value
138       */
139      public abstract void summaryValue(int val);
140    
141      /**
142       * End the summary
143       */
144      public abstract void summaryEnd();
145    
146      /**
147       * Send all the control info for the space
148       * @param space The GCspy driver for this space
149       * @param tileNum The number of tiles
150       */
151      public abstract void sendControls(AbstractDriver space, int tileNum);
152    
153      /**
154       * Send info for this space
155       * @param info A pointer to the information (held as C string)
156       */
157      public abstract void spaceInfo(Address info);
158    
159      /**
160       * End the transmission (for this event)
161       */
162      public void endCommunication() {
163        if (DEBUG) Log.write("endComm\n");
164      }
165    }