Skip to content
Permalink
Browse files

8238355: Update Graal

Reviewed-by: kvn
  • Loading branch information
Igor Veresov
Igor Veresov committed Feb 20, 2020
1 parent 2d93a28 commit 23458bf4c56998e010415712af284866d6e88956
Showing 375 changed files with 8,538 additions and 3,576 deletions.
@@ -40,15 +40,17 @@ void NativeInstruction::wrote(int offset) {
ICache::invalidate_word(addr_at(offset));
}

#ifdef ASSERT
void NativeLoadGot::report_and_fail() const {
tty->print_cr("Addr: " INTPTR_FORMAT, p2i(instruction_address()));
tty->print_cr("Addr: " INTPTR_FORMAT " Code: %x %x %x", p2i(instruction_address()),
(has_rex ? ubyte_at(0) : 0), ubyte_at(rex_size), ubyte_at(rex_size + 1));
fatal("not a indirect rip mov to rbx");
}

void NativeLoadGot::verify() const {
if (has_rex) {
int rex = ubyte_at(0);
if (rex != rex_prefix) {
if (rex != rex_prefix && rex != rex_b_prefix) {
report_and_fail();
}
}
@@ -62,6 +64,7 @@ void NativeLoadGot::verify() const {
report_and_fail();
}
}
#endif

intptr_t NativeLoadGot::data() const {
return *(intptr_t *) got_address();
@@ -149,14 +152,30 @@ address NativeGotJump::destination() const {
return *got_entry;
}

#ifdef ASSERT
void NativeGotJump::report_and_fail() const {
tty->print_cr("Addr: " INTPTR_FORMAT " Code: %x %x %x", p2i(instruction_address()),
(has_rex() ? ubyte_at(0) : 0), ubyte_at(rex_size()), ubyte_at(rex_size() + 1));
fatal("not a indirect rip jump");
}

void NativeGotJump::verify() const {
int inst = ubyte_at(0);
if (has_rex()) {
int rex = ubyte_at(0);
if (rex != rex_prefix) {
report_and_fail();
}
}
int inst = ubyte_at(rex_size());
if (inst != instruction_code) {
tty->print_cr("Addr: " INTPTR_FORMAT " Code: 0x%x", p2i(instruction_address()),
inst);
fatal("not a indirect rip jump");
report_and_fail();
}
int modrm = ubyte_at(rex_size() + 1);
if (modrm != modrm_code) {
report_and_fail();
}
}
#endif

void NativeCall::verify() {
// Make sure code pattern is actually a call imm32 instruction.
@@ -455,31 +455,35 @@ class NativeLoadGot: public NativeInstruction {
static const bool has_rex = false;
static const int rex_size = 0;
#endif
public:

enum Intel_specific_constants {
rex_prefix = 0x48,
rex_b_prefix = 0x49,
instruction_code = 0x8b,
modrm_rbx_code = 0x1d,
modrm_rax_code = 0x05,
instruction_length = 6 + rex_size,
offset_offset = 2 + rex_size
};

address instruction_address() const { return addr_at(0); }
address rip_offset_address() const { return addr_at(offset_offset); }
int rip_offset() const { return int_at(offset_offset); }
address return_address() const { return addr_at(instruction_length); }
address got_address() const { return return_address() + rip_offset(); }

#ifdef ASSERT
void report_and_fail() const;
address instruction_address() const { return addr_at(0); }
#endif

public:
address next_instruction_address() const { return return_address(); }
intptr_t data() const;
void set_data(intptr_t data) {
intptr_t *addr = (intptr_t *) got_address();
*addr = data;
}

void verify() const;
private:
void report_and_fail() const;
DEBUG_ONLY( void verify() const );
};

inline NativeLoadGot* nativeLoadGot_at(address addr) {
@@ -607,27 +611,37 @@ inline NativeGeneralJump* nativeGeneralJump_at(address address) {
}

class NativeGotJump: public NativeInstruction {
public:
enum Intel_specific_constants {
rex_prefix = 0x41,
instruction_code = 0xff,
instruction_offset = 0,
modrm_code = 0x25,
instruction_size = 6,
rip_offset = 2
};

void verify() const;
address instruction_address() const { return addr_at(instruction_offset); }
address destination() const;
address return_address() const { return addr_at(instruction_size); }
int got_offset() const { return (jint) int_at(rip_offset); }
bool has_rex() const { return ubyte_at(0) == rex_prefix; }
int rex_size() const { return has_rex() ? 1 : 0; }

address return_address() const { return addr_at(instruction_size + rex_size()); }
int got_offset() const { return (jint) int_at(rip_offset + rex_size()); }

#ifdef ASSERT
void report_and_fail() const;
address instruction_address() const { return addr_at(0); }
#endif

public:
address got_address() const { return return_address() + got_offset(); }
address next_instruction_address() const { return addr_at(instruction_size); }
bool is_GotJump() const { return ubyte_at(0) == instruction_code; }
address next_instruction_address() const { return return_address(); }
bool is_GotJump() const { return ubyte_at(rex_size()) == instruction_code; }

address destination() const;
void set_jump_destination(address dest) {
address *got_entry = (address *) got_address();
*got_entry = dest;
}

DEBUG_ONLY( void verify() const; )
};

inline NativeGotJump* nativeGotJump_at(address addr) {
@@ -337,34 +337,43 @@ public BinaryContainer(OptionValues graalOptions, GraalHotSpotVMConfig graalHotS
private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, int gc) {
// @Checkstyle: stop
// @formatter:off
boolean[] booleanFlags = { graalHotSpotVMConfig.cAssertions, // Debug VM
graalHotSpotVMConfig.useCompressedOops,
graalHotSpotVMConfig.useCompressedClassPointers,
graalHotSpotVMConfig.useTLAB,
graalHotSpotVMConfig.useBiasedLocking,
TieredAOT.getValue(graalOptions),
graalHotSpotVMConfig.enableContended,
graalHotSpotVMConfig.restrictContended,
graphBuilderConfig.omitAssertions(),
};

int[] intFlags = { graalHotSpotVMConfig.getOopEncoding().getShift(),
graalHotSpotVMConfig.getKlassEncoding().getShift(),
graalHotSpotVMConfig.contendedPaddingWidth,
1 << graalHotSpotVMConfig.logMinObjAlignment(),
graalHotSpotVMConfig.codeSegmentSize,
gc
};
// @formatter:on
// @Checkstyle: resume

ArrayList<Boolean> booleanFlagsList = new ArrayList<>();

booleanFlagsList.addAll(Arrays.asList(graalHotSpotVMConfig.cAssertions, // Debug VM
graalHotSpotVMConfig.useCompressedOops,
graalHotSpotVMConfig.useCompressedClassPointers));
if (JavaVersionUtil.JAVA_SPEC < 15) {
// See JDK-8236224. FieldsAllocationStyle and CompactFields flags were removed in JDK15.
booleanFlagsList.add(graalHotSpotVMConfig.compactFields);
}
booleanFlagsList.addAll(Arrays.asList(graalHotSpotVMConfig.useTLAB,
graalHotSpotVMConfig.useBiasedLocking,
TieredAOT.getValue(graalOptions),
graalHotSpotVMConfig.enableContended,
graalHotSpotVMConfig.restrictContended,
graphBuilderConfig.omitAssertions()));
if (JavaVersionUtil.JAVA_SPEC < 14) {
// See JDK-8220049. Thread local handshakes are on by default since JDK14, the command line option has been removed.
booleanFlags = Arrays.copyOf(booleanFlags, booleanFlags.length + 1);
booleanFlags[booleanFlags.length - 1] = graalHotSpotVMConfig.threadLocalHandshakes;
booleanFlagsList.add(graalHotSpotVMConfig.threadLocalHandshakes);
}

byte[] booleanFlagsAsBytes = flagsToByteArray(booleanFlags);
ArrayList<Integer> intFlagsList = new ArrayList<>();
intFlagsList.addAll(Arrays.asList(graalHotSpotVMConfig.getOopEncoding().getShift(),
graalHotSpotVMConfig.getKlassEncoding().getShift(),
graalHotSpotVMConfig.contendedPaddingWidth));
if (JavaVersionUtil.JAVA_SPEC < 15) {
// See JDK-8236224. FieldsAllocationStyle and CompactFields flags were removed in JDK15.
intFlagsList.add(graalHotSpotVMConfig.fieldsAllocationStyle);
}
intFlagsList.addAll(Arrays.asList(1 << graalHotSpotVMConfig.logMinObjAlignment(),
graalHotSpotVMConfig.codeSegmentSize,
gc));

// @formatter:on
// @Checkstyle: resume

byte[] booleanFlagsAsBytes = booleanListToByteArray(booleanFlagsList);
int[] intFlags = intFlagsList.stream().mapToInt(i -> i).toArray();
int size0 = configContainer.getByteStreamSize();

// @formatter:off
@@ -381,10 +390,10 @@ private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, Grap
assert size == computedSize;
}

private static byte[] flagsToByteArray(boolean[] flags) {
byte[] byteArray = new byte[flags.length];
for (int i = 0; i < flags.length; ++i) {
byteArray[i] = boolToByte(flags[i]);
private static byte[] booleanListToByteArray(ArrayList<Boolean> list) {
byte[] byteArray = new byte[list.size()];
for (int i = 0; i < list.size(); ++i) {
byteArray[i] = boolToByte(list.get(i));
}
return byteArray;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@

import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
import org.graalvm.compiler.options.OptionValues;

import jdk.tools.jaotc.binformat.BinaryContainer;
import jdk.tools.jaotc.binformat.CodeContainer;
@@ -42,13 +43,16 @@

final class CodeSectionProcessor {

private final OptionValues optionValues;

private final TargetDescription target;

private final BinaryContainer binaryContainer;

CodeSectionProcessor(DataBuilder dataBuilder) {
this.target = dataBuilder.getBackend().getTarget();
this.binaryContainer = dataBuilder.getBinaryContainer();
this.optionValues = dataBuilder.getBackend().getRuntime().getOptions();
}

/**
@@ -131,7 +135,7 @@ void process(AOTCompiledClass compClass) {
private StubInformation addCallStub(boolean isVirtualCall) {
final int startOffset = binaryContainer.getCodeContainer().getByteStreamSize();
StubInformation stub = new StubInformation(startOffset, isVirtualCall);
ELFMacroAssembler masm = ELFMacroAssembler.getELFMacroAssembler(target);
ELFMacroAssembler masm = ELFMacroAssembler.getELFMacroAssembler(target, optionValues);
byte[] code;
if (isVirtualCall) {
code = masm.getPLTVirtualEntryCode(stub);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@

package jdk.tools.jaotc;

import org.graalvm.compiler.options.OptionValues;

import jdk.tools.jaotc.aarch64.AArch64ELFMacroAssembler;
import jdk.tools.jaotc.amd64.AMD64ELFMacroAssembler;
import jdk.vm.ci.aarch64.AArch64;
@@ -34,10 +36,10 @@

public interface ELFMacroAssembler {

static ELFMacroAssembler getELFMacroAssembler(TargetDescription target) {
static ELFMacroAssembler getELFMacroAssembler(TargetDescription target, OptionValues optionValues) {
Architecture architecture = target.arch;
if (architecture instanceof AMD64) {
return new AMD64ELFMacroAssembler(target);
return new AMD64ELFMacroAssembler(target, optionValues);
} else if (architecture instanceof AArch64) {
return new AArch64ELFMacroAssembler(target);
} else {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -62,7 +62,7 @@ private static Symbol createPltSymbol(DataBuilder dataBuilder, CompiledMethodInf
}

private static int addPltJump(DataBuilder dataBuilder) {
ELFMacroAssembler masm = ELFMacroAssembler.getELFMacroAssembler(dataBuilder.getBackend().getTarget());
ELFMacroAssembler masm = ELFMacroAssembler.getELFMacroAssembler(dataBuilder.getBackend().getTarget(), dataBuilder.getBackend().getRuntime().getOptions());
byte[] code = masm.getPLTJumpCode(); // It includes alignment nops.
int size = masm.currentEndOfInstruction();
dataBuilder.getBinaryContainer().appendCodeBytes(code, 0, code.length);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -98,7 +98,9 @@ private void createMethodMetadata(AOTCompiledClass compiledClass) {
byte[] scopeDesc = metaData.scopesDescBytes();
byte[] relocationInfo = metaData.relocBytes();
byte[] oopMapInfo = metaData.oopMaps();
// this may be null as the field does not exist before JDK 13
byte[] implicitExceptionBytes = HotSpotGraalServices.getImplicitExceptionBytes(metaData);
byte[] exceptionBytes = metaData.exceptionBytes();

// create a global symbol at this position for this method
NativeOrderOutputStream metadataStream = new NativeOrderOutputStream();
@@ -160,7 +162,7 @@ private void createMethodMetadata(AOTCompiledClass compiledClass) {
metadataStream.put(relocationInfo).align(8);

exceptionOffset.set(metadataStream.position());
metadataStream.put(metaData.exceptionBytes()).align(8);
metadataStream.put(exceptionBytes).align(8);

if (implicitExceptionBytes != null) {
implictTableOffset.set(metadataStream.position());
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -35,13 +35,14 @@
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;

import jdk.vm.ci.code.TargetDescription;
import org.graalvm.compiler.options.OptionValues;

public final class AMD64ELFMacroAssembler extends AMD64MacroAssembler implements ELFMacroAssembler {

private int currentEndOfInstruction;

public AMD64ELFMacroAssembler(TargetDescription target) {
super(target);
public AMD64ELFMacroAssembler(TargetDescription target, OptionValues optionValues) {
super(target, optionValues);
}

@Override
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -71,6 +71,14 @@ public static boolean inCompiledCode() {
public static void controlFlowAnchor() {
}

/**
* A call to this method will assume a stable dimension array if {@code t} is a constant array
* and {@code i} a constant integer.
*/
public static <T> T assumeStableDimension(T t, @SuppressWarnings("unused") int i) {
return t;
}

/**
* A call to this method will force the compiler to assume this instruction has a visible memory
* effect killing all memory locations.

0 comments on commit 23458bf

Please sign in to comment.