@Override public String getMessage() { String message = super.getMessage(); StringBuilder sb = new StringBuilder(); sb.append( "Failed to allocate " ).append( attemptedAllocationSizeBytes ).append( " bytes. " ); sb.append( "So far " ).append( alreadyAllocatedBytes ); sb.append( " bytes have already been successfully allocated. " ); sb.append( "The system currently has " ); appendBytes( sb, getTotalPhysicalMemory() ).append( " total physical memory, " ); appendBytes( sb, getCommittedVirtualMemory() ).append( " committed virtual memory, and " ); appendBytes( sb, getFreePhysicalMemory() ).append( " free physical memory. " ); sb.append( "Relevant system properties: " ); appendSysProp( sb, "java.vm.name" ); appendSysProp( sb.append( ", " ), "java.vm.vendor" ); appendSysProp( sb.append( ", " ), "os.arch" ); if ( getCause() instanceof OutOfMemoryError ) { sb.append( ". The allocation was refused by the operating system" ); } if ( message != null ) { sb.append( ": " ).append( message ); } else { sb.append( '.' ); } return sb.toString(); }
/** * Allocate a block of memory of the given size in bytes, and return a pointer to that memory. * <p> * The memory is aligned such that it can be used for any data type. * The memory is uninitialised, so it may contain random garbage, or it may not. * * @return a pointer to the allocated memory */ public static long allocateMemory( long bytes ) throws NativeMemoryAllocationRefusedError { final long pointer; try { pointer = unsafe.allocateMemory( bytes ); } catch ( Throwable e ) { throw new NativeMemoryAllocationRefusedError( bytes, GlobalMemoryTracker.INSTANCE.usedDirectMemory(), e ); } if ( DIRTY_MEMORY ) { setMemory( pointer, bytes, (byte) 0xA5 ); } addAllocatedPointer( pointer, bytes ); GlobalMemoryTracker.INSTANCE.allocated( bytes ); return pointer; }
/** * Allocate a block of memory of the given size in bytes, and return a pointer to that memory. * <p> * The memory is aligned such that it can be used for any data type. * The memory is uninitialised, so it may contain random garbage, or it may not. * * @return a pointer to the allocated memory */ public static long allocateMemory( long bytes ) throws NativeMemoryAllocationRefusedError { final long pointer; try { pointer = unsafe.allocateMemory( bytes ); } catch ( Throwable e ) { throw new NativeMemoryAllocationRefusedError( bytes, GlobalMemoryTracker.INSTANCE.usedDirectMemory(), e ); } if ( DIRTY_MEMORY ) { setMemory( pointer, bytes, (byte) 0xA5 ); } addAllocatedPointer( pointer, bytes ); GlobalMemoryTracker.INSTANCE.allocated( bytes ); return pointer; }
@Override public String getMessage() { String message = super.getMessage(); StringBuilder sb = new StringBuilder(); sb.append( "Failed to allocate " ).append( attemptedAllocationSizeBytes ).append( " bytes. " ); sb.append( "So far " ).append( alreadyAllocatedBytes ); sb.append( " bytes have already been successfully allocated. " ); sb.append( "The system currently has " ); appendBytes( sb, getTotalPhysicalMemory() ).append( " total physical memory, " ); appendBytes( sb, getCommittedVirtualMemory() ).append( " committed virtual memory, and " ); appendBytes( sb, getFreePhysicalMemory() ).append( " free physical memory. " ); sb.append( "Relevant system properties: " ); appendSysProp( sb, "java.vm.name" ); appendSysProp( sb.append( ", " ), "java.vm.vendor" ); appendSysProp( sb.append( ", " ), "os.arch" ); if ( getCause() instanceof OutOfMemoryError ) { sb.append( ". The allocation was refused by the operating system" ); } if ( message != null ) { sb.append( ": " ).append( message ); } else { sb.append( '.' ); } return sb.toString(); }