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.objectmodel;
014
015import static org.jikesrvm.runtime.JavaSizeConstants.BYTES_IN_DOUBLE;
016import static org.jikesrvm.runtime.JavaSizeConstants.BYTES_IN_INT;
017
018import org.jikesrvm.classloader.RVMClass;
019
020public class FieldLayoutUnpacked extends FieldLayout {
021
022  private static class LayoutContext extends FieldLayoutContext {
023    private static final int NO_HOLE = -1;
024    int intHole = NO_HOLE;
025
026    LayoutContext(byte alignment) {
027      super(alignment);
028    }
029
030    LayoutContext(byte alignment, LayoutContext superLayout) {
031      super(alignment, superLayout);
032      if (superLayout != null) {
033        intHole = superLayout.intHole;
034      }
035    }
036
037    @Override
038    int nextOffset(int size, boolean isReference) {
039      int objectSize = getObjectSize();
040      if (size == BYTES_IN_DOUBLE) {
041        adjustAlignment(BYTES_IN_DOUBLE);
042        if ((objectSize & 0x7) == 0) {
043          ensureObjectSize(objectSize + BYTES_IN_DOUBLE);
044          return objectSize;
045        } else {
046          ensureObjectSize(objectSize + BYTES_IN_DOUBLE + BYTES_IN_INT);
047          intHole = objectSize;
048          return objectSize + BYTES_IN_INT;
049        }
050      } else if (intHole >= 0) {
051        int result = intHole;
052        intHole = NO_HOLE;
053        return result;
054      } else {
055        ensureObjectSize(objectSize + BYTES_IN_INT);
056        return objectSize;
057      }
058    }
059  }
060
061  public FieldLayoutUnpacked(boolean largeFieldsFirst, boolean clusterReferenceFields) {
062    super(largeFieldsFirst, clusterReferenceFields);
063  }
064
065  @Override
066  protected FieldLayoutContext getLayoutContext(RVMClass klass) {
067    return new LayoutContext((byte) klass.getAlignment(), (LayoutContext) klass.getFieldLayoutContext());
068  }
069}