Path: blob/master/runtime/bcutil/WritingCursor.cpp
5985 views
/*******************************************************************************1* Copyright (c) 2001, 2014 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*******************************************************************************/21/*22* WritingCursor.cpp23*/2425#include "ROMClassStringInternManager.hpp"26#include "WritingCursor.hpp"27#include <stdlib.h>28#include "ut_j9bcu.h"29#include "j9.h"3031void32WritingCursor::writeU8(U_8 u8Value, DataType dataType)33{34U_8 *u8Addr = (U_8 *)(_baseAddress + _count);35*u8Addr = u8Value;36_count += sizeof(U_8);37}3839void40WritingCursor::writeU16(U_16 u16Value, DataType dataType)41{42U_16 *u16Addr = (U_16 *)(_baseAddress + _count);43*u16Addr = u16Value;44_count += sizeof(U_16);45}4647void48WritingCursor::writeU32(U_32 u32Value, DataType dataType)49{50U_32 *u32Addr = (U_32 *)(_baseAddress + _count);51*u32Addr = u32Value;52_count += sizeof(U_32);53}5455void56WritingCursor::writeU64(U_32 u32ValueHigh, U_32 u32ValueLow, DataType dataType)57{58U_64 *u64Addr = (U_64 *)(_baseAddress + _count);5960#ifdef J9VM_ENV_LITTLE_ENDIAN61*u64Addr = (U_64(u32ValueLow) << 32) + u32ValueHigh;62#else63*u64Addr = (U_64(u32ValueHigh) << 32) + u32ValueLow;64#endif6566_count += sizeof(U_64);67}6869void70WritingCursor::writeUTF8(U_8* UTF8Data, U_16 UTF8Length, DataType dataType)71{72/* intern this string */73J9UTF8 *utf8Ptr = (J9UTF8 *)(_baseAddress + _count);74Cursor::writeUTF8(UTF8Data, UTF8Length, dataType);75_internManager->internString(utf8Ptr);76}7778void79WritingCursor::writeSRP(UDATA srpKey, DataType dataType)80{81J9SRP *srpAddr = (J9SRP *)(_baseAddress + _count);82*srpAddr = computeSRP(srpKey, srpAddr);83_count += sizeof(J9SRP);84}8586void87WritingCursor::writeWSRP(UDATA srpKey, DataType dataType)88{89J9WSRP *wsrpAddr = (J9WSRP *)(_baseAddress + _count);90*wsrpAddr = computeWSRP(srpKey, wsrpAddr);91_count += sizeof(J9WSRP);92}9394void95WritingCursor::writeData(U_8* bytes, UDATA length, DataType dataType)96{97U_8 *u8Addr = (U_8 *)(_baseAddress + _count);98memcpy(u8Addr, bytes, length);99_count += length;100}101102void103WritingCursor::padToAlignment(UDATA byteAlignment, DataType dataType)104{105U_8 *startAddr = (U_8 *)(_baseAddress + _count);106Cursor::padToAlignment(byteAlignment, dataType);107U_8 *endAddr = (U_8 *)(_baseAddress + _count);108memset(startAddr, 0, endAddr - startAddr);109}110111void112WritingCursor::mark(UDATA srpKey)113{114Trc_BCU_Assert_Equals(_count, getOffsetForSRPKey(srpKey));115}116117118