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
014package org.jikesrvm.tuningfork;
015
016import org.jikesrvm.runtime.Memory;
017import org.mmtk.policy.Space;
018import org.mmtk.policy.Space.SpaceVisitor;
019import com.ibm.tuningfork.tracegen.chunk.Chunk;
020
021/**
022 * A chunk to encode Space index/Space name mappings.
023 */
024public class SpaceDescriptorChunk extends Chunk {
025  private static final int SPACE_DESCRIPTOR_CHUNK_ID = (64 * 1024) + 100;
026
027  public static final int SPACE_DESCRIPTOR_COUNT_OFFSET = DATA_OFFSET;
028  public static final int SPACE_DESCRIPTOR_DATA_OFFSET = SPACE_DESCRIPTOR_COUNT_OFFSET + ENCODING_SPACE_INT;
029
030  private int numSpaces;
031
032  SpaceDescriptorChunk() {
033    super(SPACE_DESCRIPTOR_CHUNK_ID);
034
035    /* Write mapping of space ids to logical space names */
036    seek(SPACE_DESCRIPTOR_DATA_OFFSET);
037    numSpaces = 0;
038    Space.visitSpaces(new SpaceVisitor() {
039      @Override
040      public void visit(Space s) {
041        numSpaces++;
042        addInt(s.getIndex());
043        addString(s.getName());
044      }
045    });
046    int pos = getPosition();
047    seek(SPACE_DESCRIPTOR_COUNT_OFFSET);
048    addInt(numSpaces);
049    seek(pos);
050
051    /* Pages per byte */
052    addInt(Memory.getPagesize());
053
054    /* Possible heap range */
055    /* TODO: Horrific 32 bit assumption.
056     *       Matches equally bogus assumption in event definitions that use
057     *       an int to pass addresses.
058     *       MUST FIX BEFORE MERGING TO TRUNK!
059     */
060    addInt(org.mmtk.vm.VM.HEAP_START.toInt());
061    addInt(org.mmtk.vm.VM.HEAP_END.toInt());
062
063    close();
064  }
065
066}