19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "cds/metaspaceShared.hpp"
28 #include "classfile/classLoaderData.hpp"
29 #include "gc/shared/collectedHeap.hpp"
30 #include "logging/log.hpp"
31 #include "logging/logStream.hpp"
32 #include "memory/classLoaderMetaspace.hpp"
33 #include "memory/metaspace.hpp"
34 #include "memory/metaspaceCriticalAllocation.hpp"
35 #include "memory/metaspace/chunkHeaderPool.hpp"
36 #include "memory/metaspace/chunkManager.hpp"
37 #include "memory/metaspace/commitLimiter.hpp"
38 #include "memory/metaspace/internalStats.hpp"
39 #include "memory/metaspace/metaspaceCommon.hpp"
40 #include "memory/metaspace/metaspaceContext.hpp"
41 #include "memory/metaspace/metaspaceReporter.hpp"
42 #include "memory/metaspace/metaspaceSettings.hpp"
43 #include "memory/metaspace/runningCounters.hpp"
44 #include "memory/metaspace/virtualSpaceList.hpp"
45 #include "memory/metaspaceTracer.hpp"
46 #include "memory/metaspaceStats.hpp"
47 #include "memory/metaspaceUtils.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "memory/universe.hpp"
50 #include "oops/compressedOops.hpp"
51 #include "prims/jvmtiExport.hpp"
52 #include "runtime/atomic.hpp"
53 #include "runtime/globals_extension.hpp"
54 #include "runtime/init.hpp"
55 #include "runtime/java.hpp"
56 #include "services/memTracker.hpp"
57 #include "utilities/copy.hpp"
58 #include "utilities/debug.hpp"
815 CompressedClassSpaceSize));
816 }
817
818 // Initialize space
819 Metaspace::initialize_class_space(rs);
820
821 // Set up compressed class pointer encoding.
822 CompressedKlassPointers::initialize((address)rs.base(), rs.size());
823 }
824
825 #endif
826
827 // Initialize non-class virtual space list, and its chunk manager:
828 MetaspaceContext::initialize_nonclass_space_context();
829
830 _tracer = new MetaspaceTracer();
831
832 // We must prevent the very first address of the ccs from being used to store
833 // metadata, since that address would translate to a narrow pointer of 0, and the
834 // VM does not distinguish between "narrow 0 as in NULL" and "narrow 0 as in start
835 // of ccs".
836 // Before Elastic Metaspace that did not happen due to the fact that every Metachunk
837 // had a header and therefore could not allocate anything at offset 0.
838 #ifdef _LP64
839 if (using_class_space()) {
840 // The simplest way to fix this is to allocate a tiny dummy chunk right at the
841 // start of ccs and do not use it for anything.
842 MetaspaceContext::context_class()->cm()->get_chunk(metaspace::chunklevel::HIGHEST_CHUNK_LEVEL);
843 }
844 #endif
845
846 #ifdef _LP64
847 if (UseCompressedClassPointers) {
848 // Note: "cds" would be a better fit but keep this for backward compatibility.
849 LogTarget(Info, gc, metaspace) lt;
850 if (lt.is_enabled()) {
851 ResourceMark rm;
852 LogStream ls(lt);
853 CDS_ONLY(MetaspaceShared::print_on(&ls);)
854 Metaspace::print_compressed_class_space(&ls);
855 CompressedKlassPointers::print_mode(&ls);
856 }
857 }
858 #endif
859
860 }
861
862 void Metaspace::post_initialize() {
863 MetaspaceGC::post_initialize();
864 }
865
866 size_t Metaspace::max_allocation_word_size() {
867 return metaspace::chunklevel::MAX_CHUNK_WORD_SIZE;
868 }
869
870 // This version of Metaspace::allocate does not throw OOM but simply returns NULL, and
871 // is suitable for calling from non-Java threads.
872 // Callers are responsible for checking null.
873 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
874 MetaspaceObj::Type type) {
875 assert(word_size <= Metaspace::max_allocation_word_size(),
876 "allocation size too large (" SIZE_FORMAT ")", word_size);
877
878 assert(loader_data != NULL, "Should never pass around a NULL loader_data. "
879 "ClassLoaderData::the_null_class_loader_data() should have been used.");
880
881 // Deal with concurrent unloading failed allocation starvation
882 MetaspaceCriticalAllocation::block_if_concurrent_purge();
883
884 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
885
886 // Try to allocate metadata.
887 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
888
889 if (result != NULL) {
|
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "cds/metaspaceShared.hpp"
28 #include "classfile/classLoaderData.hpp"
29 #include "gc/shared/collectedHeap.hpp"
30 #include "logging/log.hpp"
31 #include "logging/logStream.hpp"
32 #include "memory/classLoaderMetaspace.hpp"
33 #include "memory/metaspace.hpp"
34 #include "memory/metaspaceCriticalAllocation.hpp"
35 #include "memory/metaspace/chunkHeaderPool.hpp"
36 #include "memory/metaspace/chunkManager.hpp"
37 #include "memory/metaspace/commitLimiter.hpp"
38 #include "memory/metaspace/internalStats.hpp"
39 #include "memory/metaspace/metaspaceAlignment.hpp"
40 #include "memory/metaspace/metaspaceCommon.hpp"
41 #include "memory/metaspace/metaspaceContext.hpp"
42 #include "memory/metaspace/metaspaceReporter.hpp"
43 #include "memory/metaspace/metaspaceSettings.hpp"
44 #include "memory/metaspace/runningCounters.hpp"
45 #include "memory/metaspace/virtualSpaceList.hpp"
46 #include "memory/metaspaceTracer.hpp"
47 #include "memory/metaspaceStats.hpp"
48 #include "memory/metaspaceUtils.hpp"
49 #include "memory/resourceArea.hpp"
50 #include "memory/universe.hpp"
51 #include "oops/compressedOops.hpp"
52 #include "prims/jvmtiExport.hpp"
53 #include "runtime/atomic.hpp"
54 #include "runtime/globals_extension.hpp"
55 #include "runtime/init.hpp"
56 #include "runtime/java.hpp"
57 #include "services/memTracker.hpp"
58 #include "utilities/copy.hpp"
59 #include "utilities/debug.hpp"
816 CompressedClassSpaceSize));
817 }
818
819 // Initialize space
820 Metaspace::initialize_class_space(rs);
821
822 // Set up compressed class pointer encoding.
823 CompressedKlassPointers::initialize((address)rs.base(), rs.size());
824 }
825
826 #endif
827
828 // Initialize non-class virtual space list, and its chunk manager:
829 MetaspaceContext::initialize_nonclass_space_context();
830
831 _tracer = new MetaspaceTracer();
832
833 // We must prevent the very first address of the ccs from being used to store
834 // metadata, since that address would translate to a narrow pointer of 0, and the
835 // VM does not distinguish between "narrow 0 as in NULL" and "narrow 0 as in start
836 // of ccs". See CompressedKlassPointers::decode().
837 // Before JEP 387 that did not happen due to the fact that every Metachunk
838 // had a header and therefore could not allocate anything at offset 0.
839 #ifdef _LP64
840 if (using_class_space()) {
841 // The simplest way to fix this is to allocate a tiny dummy chunk right at the
842 // start of ccs and do not use it for anything.
843 MetaspaceContext::context_class()->cm()->get_chunk(metaspace::chunklevel::HIGHEST_CHUNK_LEVEL);
844 }
845 #endif
846
847 #ifdef _LP64
848 if (UseCompressedClassPointers) {
849 // Note: "cds" would be a better fit but keep this for backward compatibility.
850 LogTarget(Info, gc, metaspace) lt;
851 if (lt.is_enabled()) {
852 ResourceMark rm;
853 LogStream ls(lt);
854 CDS_ONLY(MetaspaceShared::print_on(&ls);)
855 Metaspace::print_compressed_class_space(&ls);
856 CompressedKlassPointers::print_mode(&ls);
857 }
858 }
859 #endif
860
861 }
862
863 void Metaspace::post_initialize() {
864 MetaspaceGC::post_initialize();
865 }
866
867 size_t Metaspace::max_allocation_word_size() {
868 return metaspace::chunklevel::MAX_CHUNK_WORD_SIZE;
869 }
870
871 #ifdef _LP64
872 // The largest allowed size for class space
873 size_t Metaspace::max_class_space_size() {
874 // This is a bit fuzzy. Max value of class space size depends on narrow klass pointer
875 // encoding range size and CDS, since class space shares encoding range with CDS. CDS
876 // archives are usually pretty small though, so to keep matters simple, for now we
877 // just assume a reasonable default (this is hackish; improve!).
878 const size_t slice_for_cds = M * 128;
879 assert(KlassEncodingMetaspaceMax >= (slice_for_cds * 2), "rethink this");
880 const size_t max_class_space_size = KlassEncodingMetaspaceMax - slice_for_cds;
881 return max_class_space_size;
882 }
883 #endif // _LP64
884
885 // This version of Metaspace::allocate does not throw OOM but simply returns NULL, and
886 // is suitable for calling from non-Java threads.
887 // Callers are responsible for checking null.
888 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
889 MetaspaceObj::Type type) {
890 assert(word_size <= Metaspace::max_allocation_word_size(),
891 "allocation size too large (" SIZE_FORMAT ")", word_size);
892
893 assert(loader_data != NULL, "Should never pass around a NULL loader_data. "
894 "ClassLoaderData::the_null_class_loader_data() should have been used.");
895
896 // Deal with concurrent unloading failed allocation starvation
897 MetaspaceCriticalAllocation::block_if_concurrent_purge();
898
899 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
900
901 // Try to allocate metadata.
902 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
903
904 if (result != NULL) {
|