Skip to content

Commit

Permalink
Merge branch '3.3' into 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Nov 28, 2017
2 parents 428e5e0 + 2a9ca88 commit 823ad8e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public class LargePageListIT
@Test
public void veryLargePageListsMustBeFullyAccessible() throws Exception
{
// We need roughly 4 GiBs of memory for the meta-data here, which is why this is an IT and not a Test.
// We need roughly 2 GiBs of memory for the meta-data here, which is why this is an IT and not a Test.
// We add one extra page worth of data to the size here, to avoid ending up on a "convenient" boundary.
int pageSize = (int) ByteUnit.kibiBytes( 8 );
long pageCacheSize = ByteUnit.tebiBytes( 1 ) + pageSize;
long pageCacheSize = ByteUnit.gibiBytes( 513 ) + pageSize;
int pages = Math.toIntExact( pageCacheSize / pageSize );

MemoryManager mman = new MemoryManager( ByteUnit.gibiBytes( 4 ), ALIGNMENT );
MemoryManager mman = new MemoryManager( ByteUnit.gibiBytes( 2 ), ALIGNMENT );
SwapperSet swappers = new SwapperSet();
long victimPage = VictimPageReference.getVictimPage( pageSize );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public synchronized long sumUsedMemory()
* Allocate a contiguous, aligned region of memory of the given size in bytes.
* @param bytes the number of bytes to allocate.
* @return A pointer to the allocated memory.
* @throws OutOfMemoryError if the requested memory could not be allocated.
*/
public synchronized long allocateAligned( long bytes )
{
Expand Down Expand Up @@ -129,6 +130,38 @@ protected synchronized void finalize() throws Throwable
}
}

private static long allocateNativeMemory( long size )
{
try
{
return UnsafeUtil.allocateMemory( size );
}
catch ( OutOfMemoryError e )
{
NativeMemoryAllocationRefusedError error = new NativeMemoryAllocationRefusedError( size );
try
{
error.initCause( e );
}
catch ( Throwable ignore )
{
// This can only happen if our NMARE somehow already has a cause initialised, which should not
// be the case, but it could if the JDK decided to inject a default cause in some future version.
// To avoid loosing the ability to trace this cause back, we'll add it as a suppressed exception
// instead.
try
{
error.addSuppressed( e );
}
catch ( Throwable ignore2 )
{
// Okay, we tried.
}
}
throw error;
}
}

private static class Grab
{
public final Grab next;
Expand All @@ -140,11 +173,11 @@ private static class Grab
Grab( Grab next, long size, long alignment )
{
this.next = next;
this.address = UnsafeUtil.allocateMemory( size );
this.address = allocateNativeMemory( size );
this.limit = address + size;
this.alignMask = alignment - 1;

nextAlignedPointer = nextAligned( address );
nextAlignedPointer = nextAligned( this.address );
}

Grab( Grab next, long address, long limit, long alignMask, long nextAlignedPointer )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.unsafe.impl.internal.dragons;

public class NativeMemoryAllocationRefusedError extends OutOfMemoryError
{
private final long size;

public NativeMemoryAllocationRefusedError( long size )
{
this.size = size;
}

@Override
public String getMessage()
{
String message = super.getMessage();
return "Failed to allocate " + size + " bytes; allocation refused by the operating system" +
(message == null ? "." : ": " + message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,10 @@ public static String newSharedArrayString( char[] chars )
}

/**
* Allocate a slab of memory of the given size in bytes, and return a pointer to that memory.
* 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 cleared, so all bytes are zero.
* 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.
*/
public static long allocateMemory( long sizeInBytes )
{
Expand Down

0 comments on commit 823ad8e

Please sign in to comment.