Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/amd64/codegen/AMD64GuardedDevirtualSnippet.cpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#include "x/amd64/codegen/AMD64GuardedDevirtualSnippet.hpp"
24
25
#include <stddef.h>
26
#include "codegen/GuardedDevirtualSnippet.hpp"
27
#include "codegen/CodeGenerator.hpp"
28
#include "codegen/Linkage.hpp"
29
#include "codegen/Linkage_inlines.hpp"
30
#include "il/LabelSymbol.hpp"
31
#include "il/MethodSymbol.hpp"
32
#include "il/Symbol.hpp"
33
34
uint8_t *TR::AMD64GuardedDevirtualSnippet::loadArgumentsIfNecessary(TR::Node *callNode, uint8_t *cursor, bool calculateSizeOnly, int32_t *sizeOfFlushArea)
35
{
36
if (!_realMethodSymbolReference)
37
return cursor;
38
39
TR::MethodSymbol *methodSymbol = _realMethodSymbolReference->getSymbol()->castToMethodSymbol();
40
if (isLoadArgumentsNecessary(methodSymbol))
41
{
42
// Devirtualized VMInternalNatives have their args evaluated to the
43
// stack, so we must load them into regs before the vft dispatch
44
TR::Linkage *linkage = cg()->getLinkage(methodSymbol->getLinkageConvention());
45
cursor = linkage->loadArguments(callNode, cursor, calculateSizeOnly, sizeOfFlushArea, false);
46
}
47
return cursor;
48
}
49
50
uint8_t *TR::AMD64GuardedDevirtualSnippet::emitSnippetBody()
51
{
52
uint8_t *buffer = cg()->getBinaryBufferCursor();
53
uint8_t *cursor = loadArgumentsIfNecessary(getNode(), buffer, false, NULL);
54
cg()->setBinaryBufferCursor(cursor);
55
cursor = TR::X86GuardedDevirtualSnippet::emitSnippetBody();
56
getSnippetLabel()->setCodeLocation(buffer);
57
cg()->setBinaryBufferCursor(buffer);
58
return cursor;
59
}
60
61
uint32_t TR::AMD64GuardedDevirtualSnippet::getLength(int32_t estimatedSnippetStart)
62
{
63
int32_t sizeOfFlushArea = 0;
64
loadArgumentsIfNecessary(getNode(), (uint8_t*)0 + estimatedSnippetStart, true, &sizeOfFlushArea);
65
return sizeOfFlushArea + TR::X86GuardedDevirtualSnippet::getLength(estimatedSnippetStart + sizeOfFlushArea);
66
}
67
68
bool TR::AMD64GuardedDevirtualSnippet::isLoadArgumentsNecessary(TR::MethodSymbol *methodSymbol)
69
{
70
return (methodSymbol && methodSymbol->isVMInternalNative());
71
}
72
73