Path: blob/master/runtime/compiler/codegen/J9WatchedInstanceFieldSnippet.cpp
6000 views
/*******************************************************************************1* Copyright (c) 2019, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122#include "codegen/J9WatchedInstanceFieldSnippet.hpp"23#include "codegen/Relocation.hpp"2425TR::J9WatchedInstanceFieldSnippet::J9WatchedInstanceFieldSnippet(TR::CodeGenerator *cg, TR::Node *node, J9Method *m, UDATA loc, UDATA os)26: TR::Snippet(cg, node, generateLabelSymbol(cg), false)27{28instanceFieldData.method = m;29instanceFieldData.location = loc;30instanceFieldData.offset = os;31}3233uint8_t *TR::J9WatchedInstanceFieldSnippet::emitSnippetBody()34{35uint8_t *cursor = cg()->getBinaryBufferCursor();36getSnippetLabel()->setCodeLocation(cursor);37TR::Node *node = getNode();3839// We emit the dataSnippet based on the assumption that the J9JITWatchedInstanceFieldData structure is laid out as below:40/* typedef struct J9JITWatchedInstanceFieldData {41J9Method *method; // Currently executing method42UDATA location; // Bytecode PC index43UDATA offset; // Field offset (not including header)44} J9JITWatchedInstanceFieldData; */4546// Emit each field and add a relocation record (for AOT compiles) for any field if needed.4748J9JITWatchedInstanceFieldData *str = reinterpret_cast<J9JITWatchedInstanceFieldData *>(cursor);49str->method = instanceFieldData.method;50str->location = instanceFieldData.location;51str->offset = instanceFieldData.offset;5253if (cg()->comp()->getOption(TR_UseSymbolValidationManager))54{55cg()->addExternalRelocation(56new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor + offsetof(J9JITWatchedInstanceFieldData, method), reinterpret_cast<uint8_t *>(instanceFieldData.method), reinterpret_cast<uint8_t *>(TR::SymbolType::typeMethod), TR_SymbolFromManager, cg()),57__FILE__,58__LINE__,59node);60}61else62{63cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor + offsetof(J9JITWatchedInstanceFieldData, method), NULL, TR_RamMethod, cg()), __FILE__, __LINE__, node);64}65cursor += sizeof(J9JITWatchedInstanceFieldData);6667return cursor;68}6970void TR::J9WatchedInstanceFieldSnippet::print(TR::FILE *pOutFile, TR_Debug *debug)71{72uint8_t *bufferPos = getSnippetLabel()->getCodeLocation();7374debug->printSnippetLabel(pOutFile, getSnippetLabel(), bufferPos, "J9WatchedInstanceFieldSnippet");7576debug->printPrefix(pOutFile, NULL, bufferPos, sizeof(J9Method *));77trfprintf(pOutFile, "DC \t%p \t\t# J9Method", *(reinterpret_cast<J9Method **>(bufferPos)));78bufferPos += sizeof(J9Method *);7980debug->printPrefix(pOutFile, NULL, bufferPos, sizeof(UDATA));81trfprintf(pOutFile, "DC \t%lu \t\t# location", *(reinterpret_cast<UDATA *>(bufferPos)));82bufferPos += sizeof(UDATA);8384debug->printPrefix(pOutFile, NULL, bufferPos, sizeof(UDATA));85trfprintf(pOutFile, "DC \t%lu \t\t# offset", *(reinterpret_cast<UDATA *>(bufferPos)));86bufferPos += sizeof(UDATA);87}88899091