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