8274322: Problems with oopDesc construction

Reviewed-by: dholmes, stefank
This commit is contained in:
Kim Barrett 2021-10-01 00:25:35 +00:00
parent a8edd1b360
commit 2e690ba8bd
5 changed files with 35 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
#define SHARE_OOPS_INSTANCEOOP_HPP #define SHARE_OOPS_INSTANCEOOP_HPP
#include "oops/oop.hpp" #include "oops/oop.hpp"
#include <type_traits>
// An instanceOop is an instance of a Java Class // An instanceOop is an instance of a Java Class
// Evaluating "new HashTable()" will create an instanceOop. // Evaluating "new HashTable()" will create an instanceOop.
@ -44,4 +45,7 @@ class instanceOopDesc : public oopDesc {
} }
}; };
// See similar requirement for oopDesc.
static_assert(std::is_trivially_default_constructible<instanceOopDesc>::value, "required");
#endif // SHARE_OOPS_INSTANCEOOP_HPP #endif // SHARE_OOPS_INSTANCEOOP_HPP

View File

@ -73,10 +73,13 @@ class markWord {
public: public:
explicit markWord(uintptr_t value) : _value(value) {} explicit markWord(uintptr_t value) : _value(value) {}
markWord() { /* uninitialized */} markWord() = default; // Doesn't initialize _value.
// It is critical for performance that this class be trivially // It is critical for performance that this class be trivially
// destructable, copyable, and assignable. // destructable, copyable, and assignable.
~markWord() = default;
markWord(const markWord&) = default;
markWord& operator=(const markWord&) = default;
static markWord from_pointer(void* ptr) { static markWord from_pointer(void* ptr) {
return markWord((uintptr_t)ptr); return markWord((uintptr_t)ptr);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@
#include "oops/arrayOop.hpp" #include "oops/arrayOop.hpp"
#include "utilities/align.hpp" #include "utilities/align.hpp"
#include <type_traits>
class Klass; class Klass;
@ -109,4 +110,7 @@ public:
void oop_iterate_range(OopClosureType* blk, int start, int end); void oop_iterate_range(OopClosureType* blk, int start, int end);
}; };
// See similar requirement for oopDesc.
static_assert(std::is_trivially_default_constructible<objArrayOopDesc>::value, "required");
#endif // SHARE_OOPS_OBJARRAYOOP_HPP #endif // SHARE_OOPS_OBJARRAYOOP_HPP

View File

@ -31,7 +31,9 @@
#include "oops/markWord.hpp" #include "oops/markWord.hpp"
#include "oops/metadata.hpp" #include "oops/metadata.hpp"
#include "runtime/atomic.hpp" #include "runtime/atomic.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp" #include "utilities/macros.hpp"
#include <type_traits>
// oopDesc is the top baseclass for objects classes. The {name}Desc classes describe // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
// the format of Java objects so the fields can be accessed from C++. // the format of Java objects so the fields can be accessed from C++.
@ -57,7 +59,14 @@ class oopDesc {
narrowKlass _compressed_klass; narrowKlass _compressed_klass;
} _metadata; } _metadata;
// There may be ordering constraints on the initialization of fields that
// make use of the C++ copy/assign incorrect.
NONCOPYABLE(oopDesc);
public: public:
// Must be trivial; see verifying static assert after the class.
oopDesc() = default;
inline markWord mark() const; inline markWord mark() const;
inline markWord mark_acquire() const; inline markWord mark_acquire() const;
inline markWord* mark_addr() const; inline markWord* mark_addr() const;
@ -311,4 +320,11 @@ class oopDesc {
DEBUG_ONLY(bool get_UseG1GC();) DEBUG_ONLY(bool get_UseG1GC();)
}; };
// An oopDesc is not initialized via a constructor. Space is allocated in
// the Java heap, and static functions provided here on HeapWord* are used
// to fill in certain parts of that memory. The allocated memory is then
// treated as referring to an oopDesc. For that to be valid, the oopDesc
// class must have a trivial default constructor (C++14 3.8/1).
static_assert(std::is_trivially_default_constructible<oopDesc>::value, "required");
#endif // SHARE_OOPS_OOP_HPP #endif // SHARE_OOPS_OOP_HPP

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@
#include "oops/arrayOop.hpp" #include "oops/arrayOop.hpp"
#include "oops/typeArrayKlass.hpp" #include "oops/typeArrayKlass.hpp"
#include <type_traits>
// A typeArrayOop is an array containing basic types (non oop elements). // A typeArrayOop is an array containing basic types (non oop elements).
// It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs} // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
@ -134,4 +135,7 @@ private:
inline int object_size(const TypeArrayKlass* tk) const; inline int object_size(const TypeArrayKlass* tk) const;
}; };
// See similar requirement for oopDesc.
static_assert(std::is_trivially_default_constructible<typeArrayOopDesc>::value, "required");
#endif // SHARE_OOPS_TYPEARRAYOOP_HPP #endif // SHARE_OOPS_TYPEARRAYOOP_HPP