<commit_before>/*
 * 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.flink.core.memory;

import java.lang.reflect.Field;
import java.nio.ByteOrder;

/**
 * Utility class for native (unsafe) memory accesses.
 */
public class MemoryUtils {
	
	/**
	 * The "unsafe", which can be used to perform native memory accesses.
	 */
	@SuppressWarnings("restriction")
	public static final sun.misc.Unsafe UNSAFE = getUnsafe();
	
	/**
	 * The native byte order of the platform on which the system currently runs.
	 */
	public static final ByteOrder NATIVE_BYTE_ORDER = getByteOrder();
	
	
	@SuppressWarnings("restriction")
	private static sun.misc.Unsafe getUnsafe() {
		try {
			Field unsafeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
			unsafeField.setAccessible(true);
			return (sun.misc.Unsafe) unsafeField.get(null);
		} catch (SecurityException e) {
			throw new RuntimeException("Could not access the unsafe handle.", e);
		} catch (NoSuchFieldException e) {
			throw new RuntimeException("The static unsafe handle field was not be found.");
		} catch (IllegalArgumentException e) {
			throw new RuntimeException("Bug: Illegal argument reflection access for static field.");
		} catch (IllegalAccessException e) {
			throw new RuntimeException("Access to the unsafe handle is forbidden by the runtime.", e);
		}
	}
	
	@SuppressWarnings("restriction")
	private static ByteOrder getByteOrder() {
		final byte[] bytes = new byte[8];
		final long value = 0x12345678900abdefL;
		UNSAFE.putLong(bytes, (long) UNSAFE.arrayBaseOffset(byte[].class), value);
		
		final int lower = bytes[0] & 0xff;
		final int higher = bytes[7] & 0xff;
		
		if (lower == 0x12 && higher == 0xef) {
			return ByteOrder.BIG_ENDIAN;
		} else if (lower == 0xef && higher == 0x12) {
			return ByteOrder.LITTLE_ENDIAN;
		} else {
			throw new RuntimeException("Unrecognized byte order.");
		}
	}
	
	
	private MemoryUtils() {}
}
<commit_msg>[hotfix] Determing native byte order via ByteOrder.nativeOrder()<commit_after>/*
 * 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.flink.core.memory;

import java.lang.reflect.Field;
import java.nio.ByteOrder;

/**
 * Utility class for native (unsafe) memory accesses.
 */
public class MemoryUtils {
	
	/**
	 * The "unsafe", which can be used to perform native memory accesses.
	 */
	@SuppressWarnings("restriction")
	public static final sun.misc.Unsafe UNSAFE = getUnsafe();
	
	/**
	 * The native byte order of the platform on which the system currently runs.
	 */
	public static final ByteOrder NATIVE_BYTE_ORDER = getByteOrder();
	
	
	@SuppressWarnings("restriction")
	private static sun.misc.Unsafe getUnsafe() {
		try {
			Field unsafeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
			unsafeField.setAccessible(true);
			return (sun.misc.Unsafe) unsafeField.get(null);
		} catch (SecurityException e) {
			throw new RuntimeException("Could not access the unsafe handle.", e);
		} catch (NoSuchFieldException e) {
			throw new RuntimeException("The static unsafe handle field was not be found.");
		} catch (IllegalArgumentException e) {
			throw new RuntimeException("Bug: Illegal argument reflection access for static field.");
		} catch (IllegalAccessException e) {
			throw new RuntimeException("Access to the unsafe handle is forbidden by the runtime.", e);
		}
	}
	
	@SuppressWarnings("restriction")
	private static ByteOrder getByteOrder() {
		return ByteOrder.nativeOrder();
	}
	
	
	private MemoryUtils() {}
}

{'fraction_non_alphanumeric': 0.09301860372074415, 'fraction_numerical': 0.006601320264052811, 'mean_word_length': 4.122950819672131, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021528', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1350, 'n_words': 534}