Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8281522: Rename ADLC classes which have the same name as hotspot vari…
…ants

Reviewed-by: neliasso, kvn
  • Loading branch information
tstuefe committed Feb 11, 2022
1 parent 84868e3 commit eee6a56
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 109 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, 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
Expand All @@ -24,7 +24,7 @@

#include "adlc.hpp"

void* AllocateHeap(size_t size) {
void* AdlAllocateHeap(size_t size) {
unsigned char* ptr = (unsigned char*) malloc(size);
if (ptr == NULL && size != 0) {
fprintf(stderr, "Error: Out of memory in ADLC\n"); // logging can cause crash!
Expand All @@ -34,7 +34,7 @@ void* AllocateHeap(size_t size) {
return ptr;
}

void* ReAllocateHeap(void* old_ptr, size_t size) {
void* AdlReAllocateHeap(void* old_ptr, size_t size) {
unsigned char* ptr = (unsigned char*) realloc(old_ptr, size);
if (ptr == NULL && size != 0) {
fprintf(stderr, "Error: Out of memory in ADLC\n"); // logging can cause crash!
Expand All @@ -44,77 +44,77 @@ void* ReAllocateHeap(void* old_ptr, size_t size) {
return ptr;
}

void* Chunk::operator new(size_t requested_size, size_t length) throw() {
return CHeapObj::operator new(requested_size + length);
void* AdlChunk::operator new(size_t requested_size, size_t length) throw() {
return AdlCHeapObj::operator new(requested_size + length);
}

void Chunk::operator delete(void* p, size_t length) {
CHeapObj::operator delete(p);
void AdlChunk::operator delete(void* p, size_t length) {
AdlCHeapObj::operator delete(p);
}

Chunk::Chunk(size_t length) {
AdlChunk::AdlChunk(size_t length) {
_next = NULL; // Chain on the linked list
_len = length; // Save actual size
}

//------------------------------chop-------------------------------------------
void Chunk::chop() {
Chunk *k = this;
void AdlChunk::chop() {
AdlChunk *k = this;
while( k ) {
Chunk *tmp = k->_next;
AdlChunk *tmp = k->_next;
// clear out this chunk (to detect allocation bugs)
memset(k, 0xBE, k->_len);
free(k); // Free chunk (was malloc'd)
k = tmp;
}
}

void Chunk::next_chop() {
void AdlChunk::next_chop() {
_next->chop();
_next = NULL;
}

//------------------------------Arena------------------------------------------
Arena::Arena( size_t init_size ) {
//------------------------------AdlArena------------------------------------------
AdlArena::AdlArena( size_t init_size ) {
init_size = (init_size+3) & ~3;
_first = _chunk = new (init_size) Chunk(init_size);
_first = _chunk = new (init_size) AdlChunk(init_size);
_hwm = _chunk->bottom(); // Save the cached hwm, max
_max = _chunk->top();
set_size_in_bytes(init_size);
}

Arena::Arena() {
_first = _chunk = new (Chunk::init_size) Chunk(Chunk::init_size);
AdlArena::AdlArena() {
_first = _chunk = new (AdlChunk::init_size) AdlChunk(AdlChunk::init_size);
_hwm = _chunk->bottom(); // Save the cached hwm, max
_max = _chunk->top();
set_size_in_bytes(Chunk::init_size);
set_size_in_bytes(AdlChunk::init_size);
}

Arena::Arena( Arena *a )
AdlArena::AdlArena( AdlArena *a )
: _chunk(a->_chunk), _hwm(a->_hwm), _max(a->_max), _first(a->_first) {
set_size_in_bytes(a->size_in_bytes());
}

//------------------------------used-------------------------------------------
// Total of all Chunks in arena
size_t Arena::used() const {
size_t sum = _chunk->_len - (_max-_hwm); // Size leftover in this Chunk
Chunk *k = _first;
while( k != _chunk) { // Whilst have Chunks in a row
sum += k->_len; // Total size of this Chunk
k = k->_next; // Bump along to next Chunk
// Total of all AdlChunks in arena
size_t AdlArena::used() const {
size_t sum = _chunk->_len - (_max-_hwm); // Size leftover in this AdlChunk
AdlChunk *k = _first;
while( k != _chunk) { // Whilst have AdlChunks in a row
sum += k->_len; // Total size of this AdlChunk
k = k->_next; // Bump along to next AdlChunk
}
return sum; // Return total consumed space.
}

//------------------------------grow-------------------------------------------
// Grow a new Chunk
void* Arena::grow( size_t x ) {
// Grow a new AdlChunk
void* AdlArena::grow( size_t x ) {
// Get minimal required size. Either real big, or even bigger for giant objs
size_t len = max(x, Chunk::size);
size_t len = max(x, AdlChunk::size);

Chunk *k = _chunk; // Get filled-up chunk address
_chunk = new (len) Chunk(len);
AdlChunk *k = _chunk; // Get filled-up chunk address
_chunk = new (len) AdlChunk(len);

if( k ) k->_next = _chunk; // Append new chunk to end of linked list
else _first = _chunk;
Expand All @@ -127,17 +127,17 @@ void* Arena::grow( size_t x ) {
}

//------------------------------calloc-----------------------------------------
// Allocate zeroed storage in Arena
void *Arena::Acalloc( size_t items, size_t x ) {
// Allocate zeroed storage in AdlArena
void *AdlArena::Acalloc( size_t items, size_t x ) {
size_t z = items*x; // Total size needed
void *ptr = Amalloc(z); // Get space
memset( ptr, 0, z ); // Zap space
return ptr; // Return space
}

//------------------------------realloc----------------------------------------
// Reallocate storage in Arena.
void *Arena::Arealloc( void *old_ptr, size_t old_size, size_t new_size ) {
// Reallocate storage in AdlArena.
void *AdlArena::Arealloc( void *old_ptr, size_t old_size, size_t new_size ) {
char *c_old = (char*)old_ptr; // Handy name
// Stupid fast special case
if( new_size <= old_size ) { // Shrink in-place
Expand All @@ -161,32 +161,32 @@ void *Arena::Arealloc( void *old_ptr, size_t old_size, size_t new_size ) {
}

//------------------------------reset------------------------------------------
// Reset this Arena to empty, and return this Arenas guts in a new Arena.
Arena *Arena::reset(void) {
Arena *a = new Arena(this); // New empty arena
// Reset this AdlArena to empty, and return this AdlArenas guts in a new AdlArena.
AdlArena *AdlArena::reset(void) {
AdlArena *a = new AdlArena(this); // New empty arena
_first = _chunk = NULL; // Normal, new-arena initialization
_hwm = _max = NULL;
return a; // Return Arena with guts
return a; // Return AdlArena with guts
}

//------------------------------contains---------------------------------------
// Determine if pointer belongs to this Arena or not.
bool Arena::contains( const void *ptr ) const {
// Determine if pointer belongs to this AdlArena or not.
bool AdlArena::contains( const void *ptr ) const {
if( (void*)_chunk->bottom() <= ptr && ptr < (void*)_hwm )
return true; // Check for in this chunk
for( Chunk *c = _first; c; c = c->_next )
for( AdlChunk *c = _first; c; c = c->_next )
if( (void*)c->bottom() <= ptr && ptr < (void*)c->top())
return true; // Check for every chunk in Arena
return false; // Not in any Chunk, so not in Arena
return true; // Check for every chunk in AdlArena
return false; // Not in any AdlChunk, so not in AdlArena
}

//-----------------------------------------------------------------------------
// CHeapObj

void* CHeapObj::operator new(size_t size) throw() {
return (void *) AllocateHeap(size);
void* AdlCHeapObj::operator new(size_t size) throw() {
return (void *) AdlAllocateHeap(size);
}

void CHeapObj::operator delete(void* p){
void AdlCHeapObj::operator delete(void* p){
free(p);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, 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
Expand All @@ -22,11 +22,11 @@
*
*/

#ifndef SHARE_ADLC_ARENA_HPP
#define SHARE_ADLC_ARENA_HPP
#ifndef SHARE_ADLC_ADLARENA_HPP
#define SHARE_ADLC_ADLARENA_HPP

void* AllocateHeap(size_t size);
void* ReAllocateHeap(void* old_ptr, size_t size);
void* AdlAllocateHeap(size_t size);
void* AdlReAllocateHeap(void* old_ptr, size_t size);

// All classes in adlc may be derived
// from one of the following allocation classes:
Expand All @@ -35,10 +35,10 @@ void* ReAllocateHeap(void* old_ptr, size_t size);
// - CHeapObj
//
// For classes used as name spaces.
// - AllStatic
// - AdlAllStatic
//

class CHeapObj {
class AdlCHeapObj {
public:
void* operator new(size_t size) throw();
void operator delete(void* p);
Expand All @@ -47,16 +47,16 @@ class CHeapObj {

// Base class for classes that constitute name spaces.

class AllStatic {
class AdlAllStatic {
public:
void* operator new(size_t size) throw();
void operator delete(void* p);
};


//------------------------------Chunk------------------------------------------
//------------------------------AdlChunk------------------------------------------
// Linked list of raw memory chunks
class Chunk: public CHeapObj {
class AdlChunk: public AdlCHeapObj {
private:
// This ordinary operator delete is needed even though not used, so the
// below two-argument operator delete will be treated as a placement
Expand All @@ -65,41 +65,41 @@ class Chunk: public CHeapObj {
public:
void* operator new(size_t size, size_t length) throw();
void operator delete(void* p, size_t length);
Chunk(size_t length);
AdlChunk(size_t length);

enum {
init_size = 1*1024, // Size of first chunk
size = 32*1024 // Default size of an Arena chunk (following the first)
size = 32*1024 // Default size of an AdlArena chunk (following the first)
};
Chunk* _next; // Next Chunk in list
size_t _len; // Size of this Chunk
AdlChunk* _next; // Next AdlChunk in list
size_t _len; // Size of this AdlChunk

void chop(); // Chop this chunk
void next_chop(); // Chop next chunk

// Boundaries of data area (possibly unused)
char* bottom() const { return ((char*) this) + sizeof(Chunk); }
char* bottom() const { return ((char*) this) + sizeof(AdlChunk); }
char* top() const { return bottom() + _len; }
};


//------------------------------Arena------------------------------------------
//------------------------------AdlArena------------------------------------------
// Fast allocation of memory
class Arena: public CHeapObj {
class AdlArena: public AdlCHeapObj {
protected:
friend class ResourceMark;
friend class HandleMark;
friend class NoHandleMark;
Chunk *_first; // First chunk
Chunk *_chunk; // current chunk
AdlChunk *_first; // First chunk
AdlChunk *_chunk; // current chunk
char *_hwm, *_max; // High water mark and max in current chunk
void* grow(size_t x); // Get a new Chunk of at least size x
void* grow(size_t x); // Get a new AdlChunk of at least size x
size_t _size_in_bytes; // Size of arena (used for memory usage tracing)
public:
Arena();
Arena(size_t init_size);
Arena(Arena *old);
~Arena() { _first->chop(); }
AdlArena();
AdlArena(size_t init_size);
AdlArena(AdlArena *old);
~AdlArena() { _first->chop(); }
char* hwm() const { return _hwm; }

// Fast allocate in the arena. Common case is: pointer test + increment.
Expand Down Expand Up @@ -137,10 +137,10 @@ class Arena: public CHeapObj {
void *Acalloc( size_t items, size_t x );
void *Arealloc( void *old_ptr, size_t old_size, size_t new_size );

// Reset this Arena to empty, and return this Arenas guts in a new Arena.
Arena *reset(void);
// Reset this AdlArena to empty, and return this AdlArenas guts in a new AdlArena.
AdlArena *reset(void);

// Determine if pointer belongs to this Arena or not.
// Determine if pointer belongs to this AdlArena or not.
bool contains( const void *ptr ) const;

// Total of all chunks in use (not thread-safe)
Expand All @@ -151,4 +151,4 @@ class Arena: public CHeapObj {
void set_size_in_bytes(size_t size) { _size_in_bytes = size; }
};

#endif // SHARE_ADLC_ARENA_HPP
#endif // SHARE_ADLC_ADLARENA_HPP
2 changes: 1 addition & 1 deletion src/hotspot/share/adlc/adlc.hpp
Expand Up @@ -93,7 +93,7 @@ typedef unsigned int uintptr_t;
#define max(a, b) (((a)>(b)) ? (a) : (b))

// ADLC components
#include "arena.hpp"
#include "adlArena.hpp"
#include "opto/adlcVMDeps.hpp"
#include "filebuff.hpp"
#include "dict2.hpp"
Expand Down

3 comments on commit eee6a56

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tstuefe
Copy link
Member Author

@tstuefe tstuefe commented on eee6a56 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on eee6a56 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tstuefe Could not automatically backport eee6a562 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/hotspot/share/adlc/adlArena.hpp
  • src/hotspot/share/adlc/dict2.cpp
  • src/hotspot/share/adlc/forms.cpp

To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk17u-dev:

$ git checkout -b tstuefe-backport-eee6a562
$ git fetch --no-tags https://git.openjdk.java.net/jdk eee6a5622dca683d4d6a701daa48e09e8d17b54e
$ git cherry-pick --no-commit eee6a5622dca683d4d6a701daa48e09e8d17b54e
$ # Resolve conflicts
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport eee6a5622dca683d4d6a701daa48e09e8d17b54e'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport eee6a5622dca683d4d6a701daa48e09e8d17b54e.

Please sign in to comment.