AllocExtent.java

Index Score
org.apache.derby.impl.store.raw.data
Apache Derby

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
JAVA0034JAVA0034 Missing braces in if statement
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
SIZESize of the file in bytes
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
LINESNumber of lines in the source file
COMPARISONSNumber of comparison operators
COMMENTSComment lines
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
CYCLOMATICCyclomatic complexity
DECL_COMMENTSComments in declarations
LOCLines of code
RETURNSNumber of return points from functions
ELOCEffective lines of code
INTERFACE_COMPLEXITYInterface complexity
LOGICAL_LINESNumber of statements
DOC_COMMENTNumber of javadoc comment lines
LOOPSNumber of loops
OPERATORSNumber of operators
JAVA0117JAVA0117 Missing javadoc: method 'method'
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
JAVA0076JAVA0076 Use of magic number
JAVA0160JAVA0160 Method does not throw specified exception
BLOCKSNumber of blocks
JAVA0173JAVA0173 Unused method parameter
WHITESPACENumber of whitespace lines
UNIQUE_OPERATORSNumber of unique operators
FUNCTIONSNumber of function declarations
PROGRAM_VOCABHalstead program vocabulary
UNIQUE_OPERANDSNumber of unique operands
PARAMSNumber of formal parameter declarations
JAVA0145JAVA0145 Tab character used in source file
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0035JAVA0035 Missing braces in for statement
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0030JAVA0030 Private field not used
BLOCK_COMMENTNumber of block comment lines
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
NEST_DEPTHMaximum nesting depth
/* Derby - Class org.apache.derby.impl.store.raw.data.AllocExtent Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package org.apache.derby.impl.store.raw.data; import org.apache.derby.iapi.services.sanity.SanityManager; import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.store.raw.ContainerHandle; import org.apache.derby.iapi.store.raw.xact.RawTransaction; import org.apache.derby.iapi.services.io.FormatableBitSet; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectInput; /** An allocation extent row manages the page status of page in the extent. AllocExtent is externalizable and is written to the AllocPage directly, without being converted to a row first. <P> <PRE> @format_id none, format implied by AllocPage's format @purpose manage page status of page in extent @upgrade @disk_layout extentOffset(long) the begin physical byte offset of the first page of this extent extentStart(long) the first logical page mananged by this extent. extentEnd(long) the last page this extent can ever hope to manage extentLength(int) the number of pages allocated in this extent extentStatus(int) status bits for the whole extent. HAS_DEALLOCATED - most likely, this extent has a deallocated page somewhere If !HAD_DEALLOCATED, the extent has no deallocated page HAS_FREE - most likely, this extent has a free page somewhere If !HAS_FREE, there is no free page in the extent ALL_FREE - most likely, this extent only has free pages, good candidate for shrinking the file. If !ALL_FREE, the extent is not all free HAS_UNFILLED_PAGES - most likely, this extent has unfilled pages. if !HAS_UNFILLED_PAGES, all pages are filled KEEP_UNFILLED_PAGES - this extent keeps track of unfilled pages (post v1.3). If not set, this extent has no notion of unfilled page and has no unFilledPage bitmap. NO_DEALLOC_PAGE_MAP - this extents do not have a dealloc and a free page bit maps. Prior to 2.0, there are 2 bit maps, a deallocate page bit map and a free page bit map. Cloudscape 2.0 and later merged the dealloc page bit map into the free page bit map. RETIRED - this extent contains only 'retired' pages, never use any page from this extent. The pages don't actually exist, i.e., it maps to nothing (physicalOffset is garbage). The purpose of this extent is to blot out a range of logical page numbers that no longer exists for this container. Use this to reuse a physical page when a logical page has exhausted all recordId or for logical pages that has been shrunk out. preAllocLength(int) the number of pages that have been preallocated reserved1(int) reserved2(long) reserved for future use reserved3(long) reserved for future use FreePages(bit) bitmap of free pages Bit[i] is ON iff page i is free for immediate (re)use. [ on disk version before 2.0 deAllocPages(bit) bitmap of deallocated pages Bit[i] is ON iff page i has been deallocated. ] unFilledPages(bit) bitmap of pages that has free space Bit[i] is ON if page i is likely to be < 1/2 full org.apache.derby.iapi.services.io.FormatableBitSet is used to store the bit map. FormatableBitSet is an externalizable class. @end_format <PRE> A page can have the following logical state: <BR>Free - a page that is free to be used <BR>Valid - a page that is currently in use <P> There is another type of transitional pages which pages that have been allocated on disk but has not yet been used. These pages are Free. <P> Bit[K] freePages Bit[i] is ON iff page i maybe free for reuse. User must get the dealloc page lock on the free page to make sure the transaction. <P> K is the size of the bit array, it must be >= length. @see AllocPage */ public class AllocExtent implements Externalizable { private long extentOffset; // begin physical offset private long extentStart; // first logical page number private long extentEnd; // last logical page number // page[extentStart] to page[extentEnd] are the pages in the range of this // alloc extent. // page[exentStart] to page[extentStart+extentLength-1] are actually // allocated in this extent // when the extent is completely allocated, // extentEnd == extentStart+extentLength -1 private int extentLength; // number of pages allocated in the extent int extentStatus; private int preAllocLength; private int reserved1; private long reserved2; private long reserved3; // extent Status bits private static final int HAS_DEALLOCATED = 0x1; private static final int HAS_FREE = 0x2; private static final int ALL_FREE = 0x4; private static final int HAS_UNFILLED_PAGES = 0x10; private static final int KEEP_UNFILLED_PAGES = 0x10000000; private static final int NO_DEALLOC_PAGE_MAP = 0x20000000; private static final int RETIRED = 0x8; /** public Per Page status */ protected static final int ALLOCATED_PAGE = 0; protected static final int DEALLOCATED_PAGE = 1; protected static final int FREE_PAGE = 2; // a page which is not a freePage is a regular old // allocated page. Only an allocated page can be unFilled. FormatableBitSet freePages; FormatableBitSet unFilledPages; /** Statically calculates how many pages this extent can manage given the availspace number of bytes to store this extent in if read/writeExternal changes, this must change too */ protected static int MAX_RANGE(int availspace) { /* extent Offset, Start, End, Length, Status, preAllocLength, reserved1,2,3 */ int bookkeeping = 8 /* offset */ + 8 /* start */ + 8 /* end */ + 4 /* length */ + 4 /* status */ + 4 /* preAllocLength */ + 4 /* reserved1 */ + 8 /* reserved2 */ + 8 /* reserved3 */; availspace -= bookkeeping; // each bit array is allowed to the 1/3 the remaining space availspace /= 3; if (availspace <= 0) return 0; // ask bit array how many bits it can store in this amount of space return FormatableBitSet.maxBitsForSpace(availspace); } /* * methods */ /* * ctors */ protected AllocExtent(long offset, // physical offset long start, // starting logical page number int length, // how many pages are in this extent int pagesize, // size of all the pages in the extent int maxlength) // initial size of the bit map arrays { if (SanityManager.DEBUG) { if (length > maxlength) SanityManager.THROWASSERT( "length " + length + " > maxlength " + maxlength); } this.extentOffset = offset; this.extentStart = start; this.extentEnd = start+maxlength-1; this.extentLength = length; preAllocLength = extentLength; if (length > 0) extentStatus = HAS_FREE | ALL_FREE ; else extentStatus = 0; extentStatus |= KEEP_UNFILLED_PAGES; // v1.3 or beyond extentStatus |= NO_DEALLOC_PAGE_MAP; // v2.0 or beyond int numbits = (1+(length/8))*8; if (numbits > maxlength) numbits = maxlength; freePages = new FormatableBitSet(numbits); unFilledPages = new FormatableBitSet(numbits); // by definition, all pages are free to begin with, no pages are // deallocated and no page is unfilled for (int i = 0; i < length; i++) freePages.set(i); } /* Copy constructor */ protected AllocExtent(AllocExtent original) { extentOffset = original.extentOffset; extentStart = original.extentStart; extentEnd = original.extentEnd; extentLength = original.extentLength; extentStatus = original.extentStatus; preAllocLength = original.preAllocLength; freePages = new FormatableBitSet(original.freePages); unFilledPages = new FormatableBitSet(original.unFilledPages); } /* * Methods of Externalizable */ public AllocExtent() { } public void writeExternal(ObjectOutput out) throws IOException { // any change to this routine must change maxRange out.writeLong(extentOffset); out.writeLong(extentStart); out.writeLong(extentEnd); out.writeInt(extentLength); out.writeInt(extentStatus); out.writeInt(preAllocLength); out.writeInt(0); // reserved1 out.writeLong(0); // reserved2 out.writeLong(0); // reserved3 freePages.writeExternal(out); unFilledPages.writeExternal(out); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // any change to this routine must change maxRange extentOffset = in.readLong(); extentStart = in.readLong(); extentEnd = in.readLong(); extentLength = in.readInt(); extentStatus = in.readInt(); preAllocLength = in.readInt(); reserved1 = in.readInt(); reserved2 = in.readLong(); reserved3 = in.readLong(); freePages = new FormatableBitSet(); // don't know how to point to it freePages.readExternal(in); // this extent is created before 2.0 if ((extentStatus & NO_DEALLOC_PAGE_MAP) == 0) { FormatableBitSet deAllocPages = new FormatableBitSet(); deAllocPages.readExternal(in); // fold this into free page bit map freePages.or(deAllocPages); extentStatus |= NO_DEALLOC_PAGE_MAP; // dealloc page map has been merged } if ((extentStatus & KEEP_UNFILLED_PAGES) == KEEP_UNFILLED_PAGES) { unFilledPages = new FormatableBitSet(); unFilledPages.readExternal(in); } else // before we keep track of unfilled pages pre 1.3 { // make sure there are enough space unFilledPages = new FormatableBitSet(freePages.getLength()); extentStatus |= KEEP_UNFILLED_PAGES; // now we keep track of them } } /* * methods specific to allocExtent */ /* * write operation that is called underneath the log * * page goes thru the following transition: * ALLOCATED_PAGE <-> deallocated page -> free page <-> ALLOCATED_PAGE * */ /** Allocate this page - this is called underneath the log record @exception StandardException Standard Derby error policy */ protected void allocPage(long pagenum) throws StandardException { if (SanityManager.DEBUG) { if (pagenum > getLastPagenum()) { // adding a brand new page, it should be at most one off from the last page if (pagenum > extentEnd) SanityManager.THROWASSERT("pagenum " + pagenum + " is out of beyond my range (" + extentStart + "," + extentEnd + ")"); if (pagenum != getLastPagenum() + 1) SanityManager.THROWASSERT( "skipping pages, lastPageNumber = " + getLastPagenum() + " pageNumber = " + pagenum + "\n"); } else { // reuseing a page, make sure it is in range and is not already in use checkInRange(pagenum); int bitnum = (int)(pagenum-extentStart); // either the pagenum is now free (do) or deallocated (undo) if (!freePages.isSet(bitnum)) { SanityManager.THROWASSERT( "trying to re-allocate a page ( " + pagenum + " ) that is already allocated "); } } } // don't know if we are redoing (from free -> valid) // or undoing (from dealloc -> valid), reset them both int bitnum = (int)(pagenum-extentStart); if (bitnum >= freePages.getLength()) // expand the bit map { int numbits = (1+(bitnum/8))*8; if (numbits > (int)(extentEnd - extentStart + 1)) numbits = (int)(extentEnd - extentStart + 1); freePages.grow(numbits); unFilledPages.grow(numbits); } // the first page to be allocated has pagenum == extentStart. int numPageAlloced = (int)(pagenum-extentStart+1); if (numPageAlloced > extentLength) { extentLength = numPageAlloced; } freePages.clear(bitnum); // do not set the unfilled bit on a newly allocated page because // we only keep track of unfilled HEAD page, not unfilled overflow // page. } /** Deallocate logical page pagenum - this is called underneath the log record. pagenum must be a page managed by this extent and it must be valid @exception StandardException Standard Derby error policy */ protected void deallocPage(long pagenum) throws StandardException { int bitnum = (int)(pagenum-extentStart); // the pagenum must now be either valid (do) or free (undo) if (SanityManager.DEBUG) { if (freePages.isSet(bitnum)) SanityManager.THROWASSERT( "trying to deallocate a deallocated page " + pagenum); } freePages.set(bitnum); unFilledPages.clear(bitnum); // deallocated page is never unfilled setExtentFreePageStatus(true); } /** * Compress free pages at end of this extent. * <p> * Search backward from end of extent and prepare data structures * to return pages at end of extent to the OS. Returns the lowest * page that can be returned to the OS. * <p> * * @return Return bit of page where all pages that follow can * be returned to the OS. **/ protected int compress( BaseContainerHandle owner, RawTransaction ntt, AllocPage alloc_page) throws StandardException { int compress_bitnum = -1; int num_pages_compressed = 0; for (int i = (extentLength - 1); i >= 0; i--) { if (freePages.isSet(i)) { compress_bitnum = i; num_pages_compressed++; } else { break; } } // new_highest_page is the last page to remain in the file after // the truncate, the above loop set compress_bitnum to lowest // free page in the set of contiguous free pages at end of extent. int new_highest_page = compress_bitnum - 1; if (num_pages_compressed > 0) { if (SanityManager.DEBUG) { for (int i = new_highest_page + 1; i < extentLength; i++) { if (!freePages.isSet(i)) { SanityManager.THROWASSERT( "compressPages with nonfree pg to truncate," + "new_highest_page = " + new_highest_page + "num_pages_truncated = " + num_pages_compressed + ";extentLength = " + extentLength + ";extentStart = " + extentStart + ";freePages.isSet(" + i + ") = " + freePages.isSet(i) + "\nextent:\n" + toDebugString()); } } SanityManager.ASSERT( (new_highest_page + num_pages_compressed + 1) == extentLength, "truncate page count did not match: " + ";new_highest_page = " + new_highest_page + ";num_pages_truncated = " + num_pages_compressed + ";extentLength = " + extentLength); // the following assert could be made invalid by a new type of // access method, but currently page 1 of btree and heap contain // control rows, so will never become free and thus should never // be compressed. if (extentStart == 1) { SanityManager.ASSERT(new_highest_page >= 0); if (num_pages_compressed >= extentLength) { SanityManager.THROWASSERT( "new_highest_page = " + new_highest_page + "num_pages_compressed = " + num_pages_compressed + "; extentLength = " + extentLength + "extent:\n" + toDebugString()); } } } /* SanityManager.DEBUG_PRINT("AllocExtent", "calling actionCompressSpaceOperation:" + ";new_highest_page = " + new_highest_page + ";num_pages_compressed = " + num_pages_compressed + ";extentLength = " + extentLength + ";extent: \n" + toDebugString()); */ owner.getAllocationActionSet().actionCompressSpaceOperation( ntt, alloc_page, new_highest_page, num_pages_compressed); return(compress_bitnum); } else { return(-1); } } protected void compressPages( int new_highest_page, int num_pages_truncated) { if (SanityManager.DEBUG) { if (new_highest_page >= 0) { for (int i = new_highest_page + 1; i < extentLength; i++) { if (!freePages.isSet(i)) { SanityManager.THROWASSERT( "compressPages with non free page to truncate," + "new_highest_page = " + new_highest_page + "num_pages_truncated = " + num_pages_truncated + ";extentLength = " + extentLength + ";extentStart = " + extentStart + ";freePages.isSet(" + i + ") = " + freePages.isSet(i) + "\nextent:\n" + toDebugString()); } } } SanityManager.ASSERT( (new_highest_page + num_pages_truncated + 1) == extentLength, "truncate page count did not match: " + ";new_highest_page = " + new_highest_page + ";num_pages_truncated = " + num_pages_truncated + ";extentLength = " + extentLength); // the following assert could be made invalid by a new type of // access method, but currently page 1 of btree and heap contain // control rows, so will never become free and thus should never // be compressed. if (extentStart == 1) { SanityManager.ASSERT(new_highest_page >= 0); SanityManager.ASSERT(num_pages_truncated < extentLength); } } if (new_highest_page >= 0) { freePages.shrink(new_highest_page + 1); unFilledPages.shrink(new_highest_page + 1); // This routine assumes the caller // will be doing the truncate, and just updates the data structures. preAllocLength = extentLength = (new_highest_page + 1); } return; } /** * Undo the compress space operation. * <p> * Undo of this operation doesn't really "undo" the operation, it just * makes sure the data structures are ok after the undo. We are * guaranteed at the point of the transaction doing the * Undo of the compress space operation fixes up the bit maps to * only point at pages within the new_highest_page range. * <p> * Prior to logging the compress space operation all pages greater * than * There are only 2 possibilities at this point: * 1) the truncate of pages greater than new_highest_page happened before * the abort took place. W * 2) * * @exception StandardException Standard exception policy. **/ protected void undoCompressPages( int new_highest_page, int num_pages_truncated) { if (new_highest_page >= 0) { freePages.shrink(new_highest_page + 1); unFilledPages.shrink(new_highest_page + 1); preAllocLength = extentLength = (new_highest_page + 1); } return; } protected long getExtentEnd() { return extentEnd; } /* * read operation that is called above the log */ /** Get a page number that is free */ protected long getFreePageNumber(long pnum) { // if we can reuse page, do so, otherwise add a brand new page if (mayHaveFreePage()) { // The last allocated page may be from a previous alloc extent, but // if that extent is full and we are the first extent that can // accomodate a new page, we may be picked. In that case, pnum may // be before the start of this extent. int i = (pnum < extentStart) ? freePages.anySetBit() : freePages.anySetBit((int)(pnum-extentStart)); if (i != -1) { if (SanityManager.DEBUG) { if (i >= extentLength) SanityManager.THROWASSERT("returned bit = " + i + " extent length = " + extentLength); } return i+extentStart; } // the hint is wrong, no free page in the extent // do this unlogged, it is just a hint, don't care if it is lost if (pnum < extentStart) setExtentFreePageStatus(false); } // maximally, we can have up to extendEnd page if (SanityManager.DEBUG) SanityManager.ASSERT(extentStart+extentLength <= extentEnd); // need to add a brand new page, current end of extent is at page // extentStart+extentLength-1; return extentStart+extentLength; } /** Get the physical offset of pagenum. If deallocOK is true, then even if pagenum is deallocated, it is OK. If deallocOK is false, then an exception is thrown if pagenum is deallocated. An exception is always thrown if pagenum is a free page @exception StandardException Standard Derby error policy */ protected long getPageOffset(long pagenum, int pagesize, boolean deallocOK) throws StandardException { return pagenum * pagesize; } /** Return the status of this extent */ protected boolean isRetired() { return ((extentStatus & RETIRED) != 0); } private boolean mayHaveFreePage() { return ((extentStatus & HAS_FREE) != 0); } private void setExtentFreePageStatus(boolean hasFree) { if (hasFree) extentStatus |= HAS_FREE; else extentStatus &= ~HAS_FREE; } protected boolean canAddFreePage(long lastAllocatedPage) { // the last page to be allocated == extentEnd if (extentStart + extentLength <= extentEnd) return true; // else, check to see if this may have any free page if (!mayHaveFreePage()) return false; // we may have a free page, but that is not certain, double check if (lastAllocatedPage < extentStart) return (freePages.anySetBit() != -1); else return ((freePages.anySetBit((int)(lastAllocatedPage-extentStart))) != -1); } /** Return the status of a particular page */ protected int getPageStatus(long pagenum) { if (SanityManager.DEBUG) checkInRange(pagenum); int status = 0; int bitnum = (int)(pagenum-extentStart); if (freePages.isSet(bitnum)) status = FREE_PAGE; else status = ALLOCATED_PAGE; return status; } /** Get the first logical page number managed by this extent. */ protected long getFirstPagenum() { return extentStart; } /** Get the last logical page number managed by this extent. */ protected long getLastPagenum() { return extentStart+extentLength-1; } /** * translate bit position in map to page number. * <p> * * @return The page number of this "bit" in the extent map. * * @exception StandardException Standard exception policy. **/ protected long getPagenum(int bit_pos) { return(extentStart + bit_pos); } /* * page preallocation */ /** * get the last preallocated pagenumber managed by this alloc page */ protected long getLastPreallocPagenum() { if (extentLength > preAllocLength) preAllocLength = extentLength; return extentStart + preAllocLength - 1 ; } /** preallocated N pages, passed in the last preallocated page number. */ protected void setLastPreallocPagenum(long preAllocPagenum) { if (SanityManager.DEBUG) SanityManager.ASSERT(preAllocPagenum >= getLastPreallocPagenum(), "setLastPreallocPagenum set to small prealloc length than before"); // cannot prealloc more than this extent can handle if (preAllocPagenum > extentEnd) preAllocPagenum = extentEnd; preAllocLength = (int)(preAllocPagenum - extentStart + 1); } /* Get the logical page number that is bigger than prevPageNumber and is a valid page. If no such page in this extent, return ContainerHandle.INVALID_PAGE_HANDLE */ protected long getNextValidPageNumber(long prevPageNumber) { long pageNum; long lastpage = getLastPagenum(); if (prevPageNumber < extentStart) pageNum = extentStart; else pageNum = prevPageNumber +1; while(pageNum <= lastpage) { int status = getPageStatus(pageNum); if (status == ALLOCATED_PAGE) break; pageNum++; } if (pageNum > lastpage) pageNum = ContainerHandle.INVALID_PAGE_NUMBER; return pageNum; } protected long getLastValidPageNumber() { long pageNum = getLastPagenum(); while(pageNum >= extentStart) { int status = getPageStatus(pageNum); if (status == ALLOCATED_PAGE) break; pageNum--; } if (pageNum < extentStart) pageNum = ContainerHandle.INVALID_PAGE_NUMBER; return pageNum; } private void checkInRange(long pagenum) { if (SanityManager.DEBUG) if (pagenum < extentStart || pagenum >= extentStart+extentLength) SanityManager.THROWASSERT( "pagenum " + pagenum + " out of range"); } protected void updateUnfilledPageInfo(AllocExtent inputExtent) { if (SanityManager.DEBUG) { if (inputExtent.unFilledPages.getLength() != unFilledPages.getLength()) { SanityManager.THROWASSERT( "inputExtent's unfilled page length " + inputExtent.unFilledPages.getLength() + " != extent's unfilled page length " + unFilledPages.getLength()); } } // just use the passed in inputExtent, we know (wink wink) that the // unfilled page info is being updated just when the allocation cache // is being invalidated. Nobody is going to have a reference to the // inputExtent after this so is it save to share the FormatableBitSet. // if we cannot guarentee that the inputExtent will be unchanged by the // caller, we need to copy it // unFilledPages = new FormatableBitSet(inputExtent.unFilledPages); // Right now, just reference it directly unFilledPages = inputExtent.unFilledPages; if (unFilledPages.anySetBit() >= 0) extentStatus |= HAS_UNFILLED_PAGES; else extentStatus &= ~HAS_UNFILLED_PAGES; } /* Keep track of unfilled pages, if the extent changed, returns true. */ protected boolean trackUnfilledPage(long pagenumber, boolean unfilled) { checkInRange(pagenumber); int bitnum = (int)(pagenumber-extentStart); boolean bitSet = unFilledPages.isSet(bitnum); if (unfilled != bitSet) { if (unfilled) { unFilledPages.set(bitnum); extentStatus |= HAS_UNFILLED_PAGES; } else unFilledPages.clear(bitnum); return true; } return false; } /** Get a page number that is unfilled, pagenum is the last page that was rejected. */ protected long getUnfilledPageNumber(long pagenum) { if ((extentStatus & HAS_UNFILLED_PAGES) == 0) return ContainerHandle.INVALID_PAGE_NUMBER; int i = unFilledPages.anySetBit(); if (i != -1) { if (i+extentStart != pagenum) return i+extentStart; else { // unfortunately, we found the same page number that // was rejected. It would be unwise to unset bit // pagenum because just because it was rejected does not mean // the page is full, the row we are trying to insert may just // be too big. If we unset it, we will never find that page // again even though it may be a perfectly good page for any // other row. Just get the next set bit. i = unFilledPages.anySetBit(i); if (i != -1) return i+extentStart; } } return ContainerHandle.INVALID_PAGE_NUMBER; } /** Get the number of used page in this extent */ protected int getAllocatedPageCount() { // allocated page is one which is not free or deallocated. int allocatedPageCount = extentLength; if (!mayHaveFreePage()) return allocatedPageCount; byte[] free = freePages.getByteArray(); int numBytes = free.length; for (int i = 0; i < numBytes; i++) { if (free[i] != 0) { for (int j = 0; j < 8; j++) { if (((1 << j) & free[i]) != 0) { allocatedPageCount--; } } } } if (SanityManager.DEBUG) { if (allocatedPageCount < 0) { SanityManager.THROWASSERT( "number of allocated page < 0, val =" + allocatedPageCount + "\nextent = " + toDebugString()); } } return allocatedPageCount; } /** Get the number of unfilled pages in this extent */ protected int getUnfilledPageCount() { int unfilledPageCount = 0; int freePagesSize = freePages.size(); for (int i = 0; i < unFilledPages.size(); i++) { if (unFilledPages.isSet(i) && (i >= freePagesSize || !freePages.isSet(i))) unfilledPageCount++; } if (SanityManager.DEBUG) SanityManager.ASSERT(unfilledPageCount >= 0, "number of unfilled pages < 0"); return unfilledPageCount; } /** Get the total number of pages in this extent */ protected int getTotalPageCount() { return extentLength; } protected String toDebugString() { if (SanityManager.DEBUG) { String str = "------------------------------------------------------------------------------\n" + "Extent map of from page " + extentStart + " to page " + extentEnd + "\n"; for (long i = extentStart; i < extentStart+extentLength; i++) { str += "\tpage " + i + ": "; switch(getPageStatus(i)) { case FREE_PAGE: str += "free page\n"; break; case ALLOCATED_PAGE: str += "valid, in use page\n"; break; } // int bitnum = (int)(i-extentStart); // if (unFilledPages.isSet(bitnum)) // str += " page is estimated to be unfilled\n"; } if (getLastPagenum() < extentEnd) str += "\tFrom " + getLastPagenum() + " to " + extentEnd + " are un-allocated pages\n"; str += "------------------------------------------------------------------------------\n"; return str; } else return null; } }

The table below shows all metrics for AllocExtent.java.

MetricValueDescription
BLOCKS82.00Number of blocks
BLOCK_COMMENT65.00Number of block comment lines
COMMENTS317.00Comment lines
COMMENT_DENSITY 0.75Comment density
COMPARISONS92.00Number of comparison operators
CYCLOMATIC119.00Cyclomatic complexity
DECL_COMMENTS34.00Comments in declarations
DOC_COMMENT178.00Number of javadoc comment lines
ELOC422.00Effective lines of code
EXEC_COMMENTS35.00Comments in executable code
EXITS30.00Procedure exits
FUNCTIONS34.00Number of function declarations
HALSTEAD_DIFFICULTY129.73Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY103.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 1.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003443.00JAVA0034 Missing braces in if statement
JAVA0035 1.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA007610.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 1.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010816.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011012.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 2.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 1.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011711.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01451441.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 3.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 3.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 1.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1063.00Number of lines in the source file
LINE_COMMENT74.00Number of line comments
LOC590.00Lines of code
LOGICAL_LINES235.00Number of statements
LOOPS10.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS973.00Number of operands
OPERATORS1883.00Number of operators
PARAMS33.00Number of formal parameter declarations
PROGRAM_LENGTH2856.00Halstead program length
PROGRAM_VOCAB304.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS70.00Number of return points from functions
SIZE31513.00Size of the file in bytes
UNIQUE_OPERANDS240.00Number of unique operands
UNIQUE_OPERATORS64.00Number of unique operators
WHITESPACE156.00Number of whitespace lines